New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swr

Package Overview
Dependencies
Maintainers
8
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swr - npm Package Compare versions

Comparing version 2.1.3 to 2.1.4

11

_internal/dist/index.d.ts

@@ -8,12 +8,12 @@ import react, { FC, PropsWithChildren, MutableRefObject } from 'react';

declare const constants_ERROR_REVALIDATE_EVENT: typeof ERROR_REVALIDATE_EVENT;
declare const constants_FOCUS_EVENT: typeof FOCUS_EVENT;
declare const constants_MUTATE_EVENT: typeof MUTATE_EVENT;
declare const constants_RECONNECT_EVENT: typeof RECONNECT_EVENT;
declare const constants_MUTATE_EVENT: typeof MUTATE_EVENT;
declare const constants_ERROR_REVALIDATE_EVENT: typeof ERROR_REVALIDATE_EVENT;
declare namespace constants {
export {
constants_ERROR_REVALIDATE_EVENT as ERROR_REVALIDATE_EVENT,
constants_FOCUS_EVENT as FOCUS_EVENT,
constants_MUTATE_EVENT as MUTATE_EVENT,
constants_RECONNECT_EVENT as RECONNECT_EVENT,
constants_MUTATE_EVENT as MUTATE_EVENT,
constants_ERROR_REVALIDATE_EVENT as ERROR_REVALIDATE_EVENT,
};

@@ -347,4 +347,5 @@ }

declare const preload: <Data = any>(key_: Key, fetcher: BareFetcher<Data>) => any;
type PreloadFetcher<Data = unknown, SWRKey extends Key = Key> = SWRKey extends () => infer Arg ? (arg: Arg) => FetcherResponse<Data> : SWRKey extends infer Arg ? (arg: Arg) => FetcherResponse<Data> : never;
declare const preload: <Data = any, SWRKey extends Key = Key, Fetcher extends BareFetcher<unknown> = PreloadFetcher<Data, SWRKey>>(key_: SWRKey, fetcher: Fetcher) => ReturnType<Fetcher>;
export { Arguments, BareFetcher, BlockingData, Broadcaster, Cache, Fetcher, FetcherResponse, FullConfiguration, GlobalState, IS_REACT_LEGACY, IS_SERVER, InternalConfiguration, Key, KeyLoader, KeyedMutator, Middleware, Mutator, MutatorCallback, MutatorConfig, MutatorFn, MutatorOptions, MutatorWrapper, OBJECT, ProviderConfiguration, PublicConfiguration, RevalidateCallback, RevalidateEvent, Revalidator, RevalidatorOptions, SWRConfig, SWRConfiguration, SWRGlobalState, SWRHook, SWRResponse, ScopedMutator, State, StateDependencies, StrictTupleKey, UNDEFINED, cache, compare, createCacheHelper, defaultConfig, defaultConfigOptions, getTimestamp, hasRequestAnimationFrame, initCache, internalMutate, isDocumentDefined, isFunction, isUndefined, isWindowDefined, mergeConfigs, mergeObjects, mutate, noop, normalize, preload, preset, rAF, constants as revalidateEvents, serialize, slowConnection, stableHash, subscribeCallback, useIsomorphicLayoutEffect, useSWRConfig, useStateWithDeps, withArgs, withMiddleware };

@@ -219,6 +219,6 @@ import React, { useEffect, useLayoutEffect, createContext, useContext, useMemo, useRef, createElement, useState, useCallback } from 'react';

__proto__: null,
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT,
FOCUS_EVENT: FOCUS_EVENT,
RECONNECT_EVENT: RECONNECT_EVENT,
MUTATE_EVENT: MUTATE_EVENT,
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT
RECONNECT_EVENT: RECONNECT_EVENT
};

@@ -585,7 +585,7 @@

const preload = (key_, fetcher)=>{
const key = serialize(key_)[0];
const [key, fnArg] = serialize(key_);
const [, , , PRELOAD] = SWRGlobalState.get(cache);
// Prevent preload to be called multiple times before used.
if (PRELOAD[key]) return PRELOAD[key];
const req = fetcher(key_);
const req = fetcher(fnArg);
PRELOAD[key] = req;

@@ -597,3 +597,3 @@ return req;

const fetcher = fetcher_ && ((...args)=>{
const key = serialize(key_)[0];
const [key] = serialize(key_);
const [, , , PRELOAD] = SWRGlobalState.get(cache);

@@ -600,0 +600,0 @@ const req = PRELOAD[key];

@@ -5,6 +5,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
// Global state used to deduplicate requests and store listeners

@@ -179,3 +175,3 @@ const SWRGlobalState = new WeakMap();

const IS_REACT_LEGACY = !React__default["default"].useId;
const IS_REACT_LEGACY = !React.useId;
const IS_SERVER = !isWindowDefined || 'Deno' in window;

@@ -227,6 +223,6 @@ // Polyfill requestAnimationFrame

__proto__: null,
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT,
FOCUS_EVENT: FOCUS_EVENT,
RECONNECT_EVENT: RECONNECT_EVENT,
MUTATE_EVENT: MUTATE_EVENT,
ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT
RECONNECT_EVENT: RECONNECT_EVENT
};

@@ -572,3 +568,3 @@

// @ts-expect-error
window.__SWR_DEVTOOLS_REACT__ = React__default["default"];
window.__SWR_DEVTOOLS_REACT__ = React;
}

@@ -594,7 +590,7 @@ };

const preload = (key_, fetcher)=>{
const key = serialize(key_)[0];
const [key, fnArg] = serialize(key_);
const [, , , PRELOAD] = SWRGlobalState.get(cache);
// Prevent preload to be called multiple times before used.
if (PRELOAD[key]) return PRELOAD[key];
const req = fetcher(key_);
const req = fetcher(fnArg);
PRELOAD[key] = req;

@@ -606,3 +602,3 @@ return req;

const fetcher = fetcher_ && ((...args)=>{
const key = serialize(key_)[0];
const [key] = serialize(key_);
const [, , , PRELOAD] = SWRGlobalState.get(cache);

@@ -693,3 +689,3 @@ const req = PRELOAD[key];

} else {
React__default["default"].startTransition(()=>rerender({}));
React.startTransition(()=>rerender({}));
}

@@ -696,0 +692,0 @@ }

@@ -33,4 +33,4 @@ import * as react from 'react';

*/
declare const _default: SWRHook;
declare const useSWR: SWRHook;
export { SWRConfig, _default as default, unstable_serialize };
export { SWRConfig, useSWR as default, unstable_serialize };

@@ -12,7 +12,6 @@ import { useRef, useMemo, useCallback, useDebugValue } from 'react';

const [EVENT_REVALIDATORS, MUTATION, FETCH] = SWRGlobalState.get(cache);
// `key` is the identifier of the SWR `data` state, `keyInfo` holds extra
// states such as `error` and `isValidating` inside,
// all of them are derived from `_key`.
// `key` is the identifier of the SWR internal state,
// `fnArg` is the argument/arguments parsed from the key, which will be passed
// to the fetcher.
// All of them are derived from `_key`.
const [key, fnArg] = serialize(_key);

@@ -34,22 +33,20 @@ // If it's the initial render of this hook.

const isEqual = (prev, current)=>{
let equal = true;
for(const _ in stateDependencies){
const t = _;
if (t === 'data') {
if (!compare(current[t], prev[t])) {
if (isUndefined(prev[t])) {
if (!compare(current[t], returnedData)) {
equal = false;
}
} else {
equal = false;
if (!compare(prev[t], current[t])) {
if (!isUndefined(prev[t])) {
return false;
}
if (!compare(returnedData, current[t])) {
return false;
}
}
} else {
if (current[t] !== prev[t]) {
equal = false;
return false;
}
}
}
return equal;
return true;
};

@@ -93,3 +90,23 @@ const getSnapshot = useMemo(()=>{

const newSnapshot = getSelectedCache(getCache());
return isEqual(newSnapshot, memorizedSnapshot) ? memorizedSnapshot : memorizedSnapshot = newSnapshot;
const compareResult = isEqual(newSnapshot, memorizedSnapshot);
if (compareResult) {
// Mentally, we should always return the `memorizedSnapshot` here
// as there's no change between the new and old snapshots.
// However, since the `isEqual` function only compares selected fields,
// the values of the unselected fields might be changed. That's
// simply because we didn't track them.
// To support the case in https://github.com/vercel/swr/pull/2576,
// we need to update these fields in the `memorizedSnapshot` too
// with direct mutations to ensure the snapshot is always up-to-date
// even for the unselected fields, but only trigger re-renders when
// the selected fields are changed.
memorizedSnapshot.data = newSnapshot.data;
memorizedSnapshot.isLoading = newSnapshot.isLoading;
memorizedSnapshot.isValidating = newSnapshot.isValidating;
memorizedSnapshot.error = newSnapshot.error;
return memorizedSnapshot;
} else {
memorizedSnapshot = newSnapshot;
return newSnapshot;
}
},

@@ -491,3 +508,3 @@ ()=>serverSnapshot

* ```
*/ var useSWR = withArgs(useSWRHandler);
*/ const useSWR = withArgs(useSWRHandler);

@@ -494,0 +511,0 @@ // useSWR

@@ -13,7 +13,6 @@ Object.defineProperty(exports, '__esModule', { value: true });

const [EVENT_REVALIDATORS, MUTATION, FETCH] = _internal.SWRGlobalState.get(cache);
// `key` is the identifier of the SWR `data` state, `keyInfo` holds extra
// states such as `error` and `isValidating` inside,
// all of them are derived from `_key`.
// `key` is the identifier of the SWR internal state,
// `fnArg` is the argument/arguments parsed from the key, which will be passed
// to the fetcher.
// All of them are derived from `_key`.
const [key, fnArg] = _internal.serialize(_key);

@@ -35,22 +34,20 @@ // If it's the initial render of this hook.

const isEqual = (prev, current)=>{
let equal = true;
for(const _ in stateDependencies){
const t = _;
if (t === 'data') {
if (!compare(current[t], prev[t])) {
if (_internal.isUndefined(prev[t])) {
if (!compare(current[t], returnedData)) {
equal = false;
}
} else {
equal = false;
if (!compare(prev[t], current[t])) {
if (!_internal.isUndefined(prev[t])) {
return false;
}
if (!compare(returnedData, current[t])) {
return false;
}
}
} else {
if (current[t] !== prev[t]) {
equal = false;
return false;
}
}
}
return equal;
return true;
};

@@ -94,3 +91,23 @@ const getSnapshot = react.useMemo(()=>{

const newSnapshot = getSelectedCache(getCache());
return isEqual(newSnapshot, memorizedSnapshot) ? memorizedSnapshot : memorizedSnapshot = newSnapshot;
const compareResult = isEqual(newSnapshot, memorizedSnapshot);
if (compareResult) {
// Mentally, we should always return the `memorizedSnapshot` here
// as there's no change between the new and old snapshots.
// However, since the `isEqual` function only compares selected fields,
// the values of the unselected fields might be changed. That's
// simply because we didn't track them.
// To support the case in https://github.com/vercel/swr/pull/2576,
// we need to update these fields in the `memorizedSnapshot` too
// with direct mutations to ensure the snapshot is always up-to-date
// even for the unselected fields, but only trigger re-renders when
// the selected fields are changed.
memorizedSnapshot.data = newSnapshot.data;
memorizedSnapshot.isLoading = newSnapshot.isLoading;
memorizedSnapshot.isValidating = newSnapshot.isValidating;
memorizedSnapshot.error = newSnapshot.error;
return memorizedSnapshot;
} else {
memorizedSnapshot = newSnapshot;
return newSnapshot;
}
},

@@ -492,3 +509,3 @@ ()=>serverSnapshot

* ```
*/ var useSWR = _internal.withArgs(useSWRHandler);
*/ const useSWR = _internal.withArgs(useSWRHandler);

@@ -510,3 +527,3 @@ // useSWR

exports.SWRConfig = SWRConfig;
exports["default"] = useSWR;
exports.default = useSWR;
exports.unstable_serialize = unstable_serialize;

@@ -5,4 +5,4 @@ import * as swr from 'swr';

declare const immutable: Middleware;
declare const _default: swr.SWRHook;
declare const useSWRImmutable: swr.SWRHook;
export { _default as default, immutable };
export { useSWRImmutable as default, immutable };

@@ -11,4 +11,4 @@ import useSWR from 'swr';

};
var index = withMiddleware(useSWR, immutable);
const useSWRImmutable = withMiddleware(useSWR, immutable);
export { index as default, immutable };
export { useSWRImmutable as default, immutable };

@@ -6,6 +6,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var useSWR__default = /*#__PURE__*/_interopDefaultLegacy(useSWR);
const immutable = (useSWRNext)=>(key, fetcher, config)=>{

@@ -18,5 +14,5 @@ // Always override all revalidate options.

};
var index = _internal.withMiddleware(useSWR__default["default"], immutable);
const useSWRImmutable = _internal.withMiddleware(useSWR, immutable);
exports["default"] = index;
exports.default = useSWRImmutable;
exports.immutable = immutable;

@@ -233,4 +233,4 @@ import { useRef, useCallback } from 'react';

};
var index = withMiddleware(useSWR, infinite);
const useSWRInfinite = withMiddleware(useSWR, infinite);
export { index as default, infinite, unstable_serialize };
export { useSWRInfinite as default, infinite, unstable_serialize };

@@ -8,6 +8,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var useSWR__default = /*#__PURE__*/_interopDefaultLegacy(useSWR);
// We have to several type castings here because `useSWRInfinite` is a special

@@ -240,6 +236,6 @@ const INFINITE_PREFIX = '$inf$';

};
var index = _internal.withMiddleware(useSWR__default["default"], infinite);
const useSWRInfinite = _internal.withMiddleware(useSWR, infinite);
exports["default"] = index;
exports.default = useSWRInfinite;
exports.infinite = infinite;
exports.unstable_serialize = unstable_serialize;

@@ -36,4 +36,4 @@ import { Arguments, BareFetcher, SWRConfiguration, SWRResponse, StrictTupleKey, Middleware } from 'swr/_internal';

declare const infinite: Middleware;
declare const _default: SWRInfiniteHook;
declare const useSWRInfinite: SWRInfiniteHook;
export { SWRInfiniteCompareFn, SWRInfiniteConfiguration, SWRInfiniteFetcher, SWRInfiniteHook, SWRInfiniteKeyLoader, SWRInfiniteResponse, _default as default, infinite, unstable_serialize };
export { SWRInfiniteCompareFn, SWRInfiniteConfiguration, SWRInfiniteFetcher, SWRInfiniteHook, SWRInfiniteKeyLoader, SWRInfiniteResponse, useSWRInfinite as default, infinite, unstable_serialize };

@@ -123,4 +123,4 @@ import { useRef, useCallback } from 'react';

* ```
*/ var index = withMiddleware(useSWR, mutation);
*/ const useSWRMutation = withMiddleware(useSWR, mutation);
export { index as default };
export { useSWRMutation as default };

@@ -7,6 +7,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var useSWR__default = /*#__PURE__*/_interopDefaultLegacy(useSWR);
const mutation = ()=>{

@@ -130,4 +126,4 @@ return (key, fetcher, config = {})=>{

* ```
*/ var index = _internal.withMiddleware(useSWR__default["default"], mutation);
*/ const useSWRMutation = _internal.withMiddleware(useSWR, mutation);
exports["default"] = index;
exports.default = useSWRMutation;

@@ -74,4 +74,4 @@ import { Key, SWRResponse } from 'swr';

*/
declare const _default: SWRMutationHook;
declare const useSWRMutation: SWRMutationHook;
export { MutationFetcher, SWRMutationConfiguration, SWRMutationHook, SWRMutationResponse, _default as default };
export { MutationFetcher, SWRMutationConfiguration, SWRMutationHook, SWRMutationResponse, useSWRMutation as default };
{
"name": "swr",
"version": "2.1.3",
"version": "2.1.4",
"description": "React Hooks library for remote data fetching",

@@ -73,2 +73,23 @@ "keywords": [

"license": "MIT",
"scripts": {
"prepare": "husky install",
"csb:install": "pnpm install",
"csb:build": "pnpm build",
"clean": "pnpm -r run clean && rimraf playwright-report test-result",
"watch": "pnpm -r run watch",
"build": "pnpm build-package _internal && pnpm build-package core && pnpm build-package infinite && pnpm build-package immutable && pnpm build-package mutation && pnpm build-package subscription",
"build:e2e": "pnpm next build e2e/site -- --profile",
"build-package": "bunchee index.ts --cwd",
"types:check": "pnpm -r run types:check",
"prepublishOnly": "pnpm clean && pnpm build",
"publish-beta": "pnpm publish --tag beta",
"format": "prettier --write ./**/*.{ts,tsx}",
"lint": "eslint . --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"coverage": "jest --coverage",
"test-typing": "tsc --noEmit -p test/type/tsconfig.json && tsc --noEmit -p test/tsconfig.json",
"test": "jest",
"test:e2e": "playwright test",
"run-all-checks": "pnpm types:check && pnpm lint && pnpm test && pnpm test-typing"
},
"lint-staged": {

@@ -81,14 +102,15 @@ "*.{ts,tsx}": [

"devDependencies": {
"@playwright/test": "^1.30.0",
"@swc/core": "^1.3.29",
"@swc/jest": "0.2.24",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react": "^14.0.0",
"@type-challenges/utils": "0.1.1",
"@types/jest": "^29.4.0",
"@types/node": "^18.11.18",
"@types/react": "^18.0.27",
"@types/react": "^18.0.38",
"@types/use-sync-external-store": "^0.0.3",
"@typescript-eslint/eslint-plugin": "5.49.0",
"@typescript-eslint/parser": "5.49.0",
"bunchee": "2.2.0",
"bunchee": "3.0.1",
"eslint": "8.32.0",

@@ -106,9 +128,7 @@ "eslint-config-prettier": "8.6.0",

"prettier": "2.8.3",
"publint": "^0.1.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "4.1.2",
"typescript": "4.9.4",
"@playwright/test": "^1.30.0",
"swr": "2.1.3"
"swr": "workspace:*",
"typescript": "4.9.4"
},

@@ -128,23 +148,3 @@ "peerDependencies": {

"use-sync-external-store": "^1.2.0"
},
"scripts": {
"csb:install": "pnpm install",
"csb:build": "pnpm build",
"clean": "pnpm -r run clean && rimraf playwright-report test-result",
"watch": "pnpm -r run watch",
"build": "pnpm build-package _internal && pnpm build-package core && pnpm build-package infinite && pnpm build-package immutable && pnpm build-package mutation && pnpm build-package subscription",
"build:e2e": "pnpm next build e2e/site -- --profile",
"build-package": "bunchee index.ts --cwd",
"types:check": "pnpm -r run types:check",
"publish-beta": "pnpm publish --tag beta",
"format": "prettier --write ./**/*.{ts,tsx}",
"lint": "eslint . --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"coverage": "jest --coverage",
"test-typing": "tsc --noEmit -p test/type/tsconfig.json && tsc --noEmit -p test/tsconfig.json",
"test-packaging": "publint",
"test": "jest",
"test:e2e": "playwright test",
"run-all-checks": "pnpm types:check && pnpm lint && pnpm test && pnpm test-typing"
}
}
}

@@ -6,6 +6,2 @@ Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var useSWR__default = /*#__PURE__*/_interopDefaultLegacy(useSWR);
const subscriptionStorage = new WeakMap();

@@ -99,5 +95,5 @@ const SUBSCRIPTION_PREFIX = '$sub$';

* ```
*/ const useSWRSubscription = _internal.withMiddleware(useSWR__default["default"], subscription);
*/ const useSWRSubscription = _internal.withMiddleware(useSWR, subscription);
exports["default"] = useSWRSubscription;
exports.default = useSWRSubscription;
exports.subscription = subscription;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc