use-sync-external-store
Advanced tools
Comparing version 0.0.0-experimental-33a32441e9-20240418 to 0.0.0-experimental-33c7bd9a-20241104
@@ -11,230 +11,86 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
} | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
function error(format) { | ||
{ | ||
{ | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
printWarning('error', format, args); | ||
"use strict"; | ||
"production" !== process.env.NODE_ENV && | ||
(function () { | ||
function is(x, y) { | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
} | ||
} | ||
function printWarning(level, format, args) { | ||
// When changing this logic, you might want to also | ||
// update consoleWithStackDev.www.js as well. | ||
{ | ||
var stack = ReactSharedInternals.getStackAddendum(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
var argsWithFormat = args.map(function (item) { | ||
return String(item); | ||
}); // Careful: RN currently depends on this prefix | ||
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it | ||
// breaks IE9: https://github.com/facebook/react/issues/13610 | ||
// eslint-disable-next-line react-internal/no-production-logging | ||
Function.prototype.apply.call(console[level], console, argsWithFormat); | ||
} | ||
} | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
// dispatch for CommonJS interop named imports. | ||
var useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
var didWarnOld18Alpha = false; | ||
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works | ||
// because of a very particular set of implementation details and assumptions | ||
// -- change any one of them and it will break. The most important assumption | ||
// is that updates are always synchronous, because concurrent rendering is | ||
// only available in versions of React that also have a built-in | ||
// useSyncExternalStore API. And we only use this shim when the built-in API | ||
// does not exist. | ||
// | ||
// Do not assume that the clever hacks used by this hook also work in general. | ||
// The point of this shim is to replace the need for hacks by other libraries. | ||
function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
getServerSnapshot) { | ||
{ | ||
if (!didWarnOld18Alpha) { | ||
if (React.startTransition !== undefined) { | ||
didWarnOld18Alpha = true; | ||
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.'); | ||
function useSyncExternalStore$2(subscribe, getSnapshot) { | ||
didWarnOld18Alpha || | ||
void 0 === React.startTransition || | ||
((didWarnOld18Alpha = !0), | ||
console.error( | ||
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release." | ||
)); | ||
var value = getSnapshot(); | ||
if (!didWarnUncachedGetSnapshot) { | ||
var cachedValue = getSnapshot(); | ||
objectIs(value, cachedValue) || | ||
(console.error( | ||
"The result of getSnapshot should be cached to avoid an infinite loop" | ||
), | ||
(didWarnUncachedGetSnapshot = !0)); | ||
} | ||
cachedValue = useState({ | ||
inst: { value: value, getSnapshot: getSnapshot } | ||
}); | ||
var inst = cachedValue[0].inst, | ||
forceUpdate = cachedValue[1]; | ||
useLayoutEffect( | ||
function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}, | ||
[subscribe, value, getSnapshot] | ||
); | ||
useEffect( | ||
function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
return subscribe(function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}); | ||
}, | ||
[subscribe] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
} // Read the current snapshot from the store on every render. Again, this | ||
// breaks the rules of React, and only works here because of specific | ||
// implementation details, most importantly that updates are | ||
// always synchronous. | ||
var value = getSnapshot(); | ||
{ | ||
if (!didWarnUncachedGetSnapshot) { | ||
var cachedValue = getSnapshot(); | ||
if (!objectIs(value, cachedValue)) { | ||
error('The result of getSnapshot should be cached to avoid an infinite loop'); | ||
didWarnUncachedGetSnapshot = true; | ||
function checkIfSnapshotChanged(inst) { | ||
var latestGetSnapshot = inst.getSnapshot; | ||
inst = inst.value; | ||
try { | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(inst, nextValue); | ||
} catch (error) { | ||
return !0; | ||
} | ||
} | ||
} // Because updates are synchronous, we don't queue them. Instead we force a | ||
// re-render whenever the subscribed state changes by updating an some | ||
// arbitrary useState hook. Then, during render, we call getSnapshot to read | ||
// the current value. | ||
// | ||
// Because we don't actually use the state returned by the useState hook, we | ||
// can save a bit of memory by storing other stuff in that slot. | ||
// | ||
// To implement the early bailout, we need to track some things on a mutable | ||
// object. Usually, we would put that in a useRef hook, but we can stash it in | ||
// our useState hook instead. | ||
// | ||
// To force a re-render, we call forceUpdate({inst}). That works because the | ||
// new object always fails an equality check. | ||
var _useState = useState({ | ||
inst: { | ||
value: value, | ||
getSnapshot: getSnapshot | ||
function useSyncExternalStore$1(subscribe, getSnapshot) { | ||
return getSnapshot(); | ||
} | ||
}), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated | ||
// in the layout phase so we can access it during the tearing check that | ||
// happens on subscribe. | ||
useLayoutEffect(function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the | ||
// commit phase if there was an interleaved mutation. In concurrent mode | ||
// this can happen all the time, but even in synchronous mode, an earlier | ||
// effect may have mutated the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
}, [subscribe, value, getSnapshot]); | ||
useEffect(function () { | ||
// Check for changes right before subscribing. Subsequent changes will be | ||
// detected in the subscription handler. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
var handleStoreChange = function () { | ||
// TODO: Because there is no cross-renderer API for batching updates, it's | ||
// up to the consumer of this library to wrap their subscription event | ||
// with unstable_batchedUpdates. Should we try to detect when this isn't | ||
// the case and print a warning in development? | ||
// The store changed. Check if the snapshot changed since the last time we | ||
// read from the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
}; // Subscribe to the store and return a clean-up function. | ||
return subscribe(handleStoreChange); | ||
}, [subscribe]); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
function checkIfSnapshotChanged(inst) { | ||
var latestGetSnapshot = inst.getSnapshot; | ||
var prevValue = inst.value; | ||
try { | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(prevValue, nextValue); | ||
} catch (error) { | ||
return true; | ||
} | ||
} | ||
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) { | ||
// Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
return getSnapshot(); | ||
} | ||
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); | ||
var isServerEnvironment = !canUseDOM; | ||
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2; | ||
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); | ||
var React = require("react"), | ||
objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue, | ||
didWarnOld18Alpha = !1, | ||
didWarnUncachedGetSnapshot = !1, | ||
shim = | ||
"undefined" === typeof window || | ||
"undefined" === typeof window.document || | ||
"undefined" === typeof window.document.createElement | ||
? useSyncExternalStore$1 | ||
: useSyncExternalStore$2; | ||
exports.useSyncExternalStore = | ||
void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim; | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); | ||
})(); | ||
} |
@@ -11,218 +11,79 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
} | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
function error(format) { | ||
{ | ||
{ | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
printWarning('error', format, args); | ||
"use strict"; | ||
"production" !== process.env.NODE_ENV && | ||
(function () { | ||
function is(x, y) { | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
} | ||
} | ||
function printWarning(level, format, args) { | ||
// When changing this logic, you might want to also | ||
// update consoleWithStackDev.www.js as well. | ||
{ | ||
var stack = ReactSharedInternals.getStackAddendum(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
var argsWithFormat = args.map(function (item) { | ||
return String(item); | ||
}); // Careful: RN currently depends on this prefix | ||
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it | ||
// breaks IE9: https://github.com/facebook/react/issues/13610 | ||
// eslint-disable-next-line react-internal/no-production-logging | ||
Function.prototype.apply.call(console[level], console, argsWithFormat); | ||
} | ||
} | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
// dispatch for CommonJS interop named imports. | ||
var useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
var didWarnOld18Alpha = false; | ||
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works | ||
// because of a very particular set of implementation details and assumptions | ||
// -- change any one of them and it will break. The most important assumption | ||
// is that updates are always synchronous, because concurrent rendering is | ||
// only available in versions of React that also have a built-in | ||
// useSyncExternalStore API. And we only use this shim when the built-in API | ||
// does not exist. | ||
// | ||
// Do not assume that the clever hacks used by this hook also work in general. | ||
// The point of this shim is to replace the need for hacks by other libraries. | ||
function useSyncExternalStore$1(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
getServerSnapshot) { | ||
{ | ||
if (!didWarnOld18Alpha) { | ||
if (React.startTransition !== undefined) { | ||
didWarnOld18Alpha = true; | ||
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.'); | ||
function useSyncExternalStore$1(subscribe, getSnapshot) { | ||
didWarnOld18Alpha || | ||
void 0 === React.startTransition || | ||
((didWarnOld18Alpha = !0), | ||
console.error( | ||
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release." | ||
)); | ||
var value = getSnapshot(); | ||
if (!didWarnUncachedGetSnapshot) { | ||
var cachedValue = getSnapshot(); | ||
objectIs(value, cachedValue) || | ||
(console.error( | ||
"The result of getSnapshot should be cached to avoid an infinite loop" | ||
), | ||
(didWarnUncachedGetSnapshot = !0)); | ||
} | ||
cachedValue = useState({ | ||
inst: { value: value, getSnapshot: getSnapshot } | ||
}); | ||
var inst = cachedValue[0].inst, | ||
forceUpdate = cachedValue[1]; | ||
useLayoutEffect( | ||
function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}, | ||
[subscribe, value, getSnapshot] | ||
); | ||
useEffect( | ||
function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
return subscribe(function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}); | ||
}, | ||
[subscribe] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
} // Read the current snapshot from the store on every render. Again, this | ||
// breaks the rules of React, and only works here because of specific | ||
// implementation details, most importantly that updates are | ||
// always synchronous. | ||
var value = getSnapshot(); | ||
{ | ||
if (!didWarnUncachedGetSnapshot) { | ||
var cachedValue = getSnapshot(); | ||
if (!objectIs(value, cachedValue)) { | ||
error('The result of getSnapshot should be cached to avoid an infinite loop'); | ||
didWarnUncachedGetSnapshot = true; | ||
function checkIfSnapshotChanged(inst) { | ||
var latestGetSnapshot = inst.getSnapshot; | ||
inst = inst.value; | ||
try { | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(inst, nextValue); | ||
} catch (error) { | ||
return !0; | ||
} | ||
} | ||
} // Because updates are synchronous, we don't queue them. Instead we force a | ||
// re-render whenever the subscribed state changes by updating an some | ||
// arbitrary useState hook. Then, during render, we call getSnapshot to read | ||
// the current value. | ||
// | ||
// Because we don't actually use the state returned by the useState hook, we | ||
// can save a bit of memory by storing other stuff in that slot. | ||
// | ||
// To implement the early bailout, we need to track some things on a mutable | ||
// object. Usually, we would put that in a useRef hook, but we can stash it in | ||
// our useState hook instead. | ||
// | ||
// To force a re-render, we call forceUpdate({inst}). That works because the | ||
// new object always fails an equality check. | ||
var _useState = useState({ | ||
inst: { | ||
value: value, | ||
getSnapshot: getSnapshot | ||
} | ||
}), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated | ||
// in the layout phase so we can access it during the tearing check that | ||
// happens on subscribe. | ||
useLayoutEffect(function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the | ||
// commit phase if there was an interleaved mutation. In concurrent mode | ||
// this can happen all the time, but even in synchronous mode, an earlier | ||
// effect may have mutated the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
}, [subscribe, value, getSnapshot]); | ||
useEffect(function () { | ||
// Check for changes right before subscribing. Subsequent changes will be | ||
// detected in the subscription handler. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
var handleStoreChange = function () { | ||
// TODO: Because there is no cross-renderer API for batching updates, it's | ||
// up to the consumer of this library to wrap their subscription event | ||
// with unstable_batchedUpdates. Should we try to detect when this isn't | ||
// the case and print a warning in development? | ||
// The store changed. Check if the snapshot changed since the last time we | ||
// read from the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst: inst | ||
}); | ||
} | ||
}; // Subscribe to the store and return a clean-up function. | ||
return subscribe(handleStoreChange); | ||
}, [subscribe]); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
function checkIfSnapshotChanged(inst) { | ||
var latestGetSnapshot = inst.getSnapshot; | ||
var prevValue = inst.value; | ||
try { | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(prevValue, nextValue); | ||
} catch (error) { | ||
return true; | ||
} | ||
} | ||
var shim = useSyncExternalStore$1; | ||
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); | ||
var React = require("react"), | ||
objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue, | ||
didWarnOld18Alpha = !1, | ||
didWarnUncachedGetSnapshot = !1; | ||
exports.useSyncExternalStore = | ||
void 0 !== React.useSyncExternalStore | ||
? React.useSyncExternalStore | ||
: useSyncExternalStore$1; | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); | ||
})(); | ||
} |
/** | ||
* @license React | ||
* use-sync-external-store-shim.native.production.min.js | ||
* use-sync-external-store-shim.native.production.js | ||
* | ||
@@ -11,133 +11,50 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
'use strict'; | ||
var React = require('react'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
"use strict"; | ||
var React = require("react"); | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
const objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
// dispatch for CommonJS interop named imports. | ||
const useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
// because of a very particular set of implementation details and assumptions | ||
// -- change any one of them and it will break. The most important assumption | ||
// is that updates are always synchronous, because concurrent rendering is | ||
// only available in versions of React that also have a built-in | ||
// useSyncExternalStore API. And we only use this shim when the built-in API | ||
// does not exist. | ||
// | ||
// Do not assume that the clever hacks used by this hook also work in general. | ||
// The point of this shim is to replace the need for hacks by other libraries. | ||
function useSyncExternalStore$1(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
getServerSnapshot) { | ||
// breaks the rules of React, and only works here because of specific | ||
// implementation details, most importantly that updates are | ||
// always synchronous. | ||
const value = getSnapshot(); | ||
// re-render whenever the subscribed state changes by updating an some | ||
// arbitrary useState hook. Then, during render, we call getSnapshot to read | ||
// the current value. | ||
// | ||
// Because we don't actually use the state returned by the useState hook, we | ||
// can save a bit of memory by storing other stuff in that slot. | ||
// | ||
// To implement the early bailout, we need to track some things on a mutable | ||
// object. Usually, we would put that in a useRef hook, but we can stash it in | ||
// our useState hook instead. | ||
// | ||
// To force a re-render, we call forceUpdate({inst}). That works because the | ||
// new object always fails an equality check. | ||
const _useState = useState({ | ||
inst: { | ||
value, | ||
getSnapshot | ||
} | ||
}), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated | ||
// in the layout phase so we can access it during the tearing check that | ||
// happens on subscribe. | ||
useLayoutEffect(() => { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the | ||
// commit phase if there was an interleaved mutation. In concurrent mode | ||
// this can happen all the time, but even in synchronous mode, an earlier | ||
// effect may have mutated the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
var objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
function useSyncExternalStore$1(subscribe, getSnapshot) { | ||
var value = getSnapshot(), | ||
_useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; | ||
useLayoutEffect( | ||
function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}, | ||
[subscribe, value, getSnapshot] | ||
); | ||
useEffect( | ||
function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
return subscribe(function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}); | ||
} | ||
}, [subscribe, value, getSnapshot]); | ||
useEffect(() => { | ||
// Check for changes right before subscribing. Subsequent changes will be | ||
// detected in the subscription handler. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
}); | ||
} | ||
const handleStoreChange = () => { | ||
// TODO: Because there is no cross-renderer API for batching updates, it's | ||
// up to the consumer of this library to wrap their subscription event | ||
// with unstable_batchedUpdates. Should we try to detect when this isn't | ||
// the case and print a warning in development? | ||
// The store changed. Check if the snapshot changed since the last time we | ||
// read from the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
}); | ||
} | ||
}; // Subscribe to the store and return a clean-up function. | ||
return subscribe(handleStoreChange); | ||
}, [subscribe]); | ||
}, | ||
[subscribe] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
function checkIfSnapshotChanged(inst) { | ||
const latestGetSnapshot = inst.getSnapshot; | ||
const prevValue = inst.value; | ||
var latestGetSnapshot = inst.getSnapshot; | ||
inst = inst.value; | ||
try { | ||
const nextValue = latestGetSnapshot(); | ||
return !objectIs(prevValue, nextValue); | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(inst, nextValue); | ||
} catch (error) { | ||
return true; | ||
return !0; | ||
} | ||
} | ||
const shim = useSyncExternalStore$1; | ||
const useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
exports.useSyncExternalStore = | ||
void 0 !== React.useSyncExternalStore | ||
? React.useSyncExternalStore | ||
: useSyncExternalStore$1; |
/** | ||
* @license React | ||
* use-sync-external-store-shim.production.min.js | ||
* use-sync-external-store-shim.production.js | ||
* | ||
@@ -11,145 +11,57 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
'use strict'; | ||
var React = require('react'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
"use strict"; | ||
var React = require("react"); | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
const objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
// dispatch for CommonJS interop named imports. | ||
const useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
// because of a very particular set of implementation details and assumptions | ||
// -- change any one of them and it will break. The most important assumption | ||
// is that updates are always synchronous, because concurrent rendering is | ||
// only available in versions of React that also have a built-in | ||
// useSyncExternalStore API. And we only use this shim when the built-in API | ||
// does not exist. | ||
// | ||
// Do not assume that the clever hacks used by this hook also work in general. | ||
// The point of this shim is to replace the need for hacks by other libraries. | ||
function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
getServerSnapshot) { | ||
// breaks the rules of React, and only works here because of specific | ||
// implementation details, most importantly that updates are | ||
// always synchronous. | ||
const value = getSnapshot(); | ||
// re-render whenever the subscribed state changes by updating an some | ||
// arbitrary useState hook. Then, during render, we call getSnapshot to read | ||
// the current value. | ||
// | ||
// Because we don't actually use the state returned by the useState hook, we | ||
// can save a bit of memory by storing other stuff in that slot. | ||
// | ||
// To implement the early bailout, we need to track some things on a mutable | ||
// object. Usually, we would put that in a useRef hook, but we can stash it in | ||
// our useState hook instead. | ||
// | ||
// To force a re-render, we call forceUpdate({inst}). That works because the | ||
// new object always fails an equality check. | ||
const _useState = useState({ | ||
inst: { | ||
value, | ||
getSnapshot | ||
} | ||
}), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated | ||
// in the layout phase so we can access it during the tearing check that | ||
// happens on subscribe. | ||
useLayoutEffect(() => { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the | ||
// commit phase if there was an interleaved mutation. In concurrent mode | ||
// this can happen all the time, but even in synchronous mode, an earlier | ||
// effect may have mutated the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
var objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useState = React.useState, | ||
useEffect = React.useEffect, | ||
useLayoutEffect = React.useLayoutEffect, | ||
useDebugValue = React.useDebugValue; | ||
function useSyncExternalStore$2(subscribe, getSnapshot) { | ||
var value = getSnapshot(), | ||
_useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }), | ||
inst = _useState[0].inst, | ||
forceUpdate = _useState[1]; | ||
useLayoutEffect( | ||
function () { | ||
inst.value = value; | ||
inst.getSnapshot = getSnapshot; | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}, | ||
[subscribe, value, getSnapshot] | ||
); | ||
useEffect( | ||
function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
return subscribe(function () { | ||
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst }); | ||
}); | ||
} | ||
}, [subscribe, value, getSnapshot]); | ||
useEffect(() => { | ||
// Check for changes right before subscribing. Subsequent changes will be | ||
// detected in the subscription handler. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
}); | ||
} | ||
const handleStoreChange = () => { | ||
// TODO: Because there is no cross-renderer API for batching updates, it's | ||
// up to the consumer of this library to wrap their subscription event | ||
// with unstable_batchedUpdates. Should we try to detect when this isn't | ||
// the case and print a warning in development? | ||
// The store changed. Check if the snapshot changed since the last time we | ||
// read from the store. | ||
if (checkIfSnapshotChanged(inst)) { | ||
// Force a re-render. | ||
forceUpdate({ | ||
inst | ||
}); | ||
} | ||
}; // Subscribe to the store and return a clean-up function. | ||
return subscribe(handleStoreChange); | ||
}, [subscribe]); | ||
}, | ||
[subscribe] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
function checkIfSnapshotChanged(inst) { | ||
const latestGetSnapshot = inst.getSnapshot; | ||
const prevValue = inst.value; | ||
var latestGetSnapshot = inst.getSnapshot; | ||
inst = inst.value; | ||
try { | ||
const nextValue = latestGetSnapshot(); | ||
return !objectIs(prevValue, nextValue); | ||
var nextValue = latestGetSnapshot(); | ||
return !objectIs(inst, nextValue); | ||
} catch (error) { | ||
return true; | ||
return !0; | ||
} | ||
} | ||
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) { | ||
// Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
// React do not expose a way to check if we're hydrating. So users of the shim | ||
// will need to track that themselves and return the correct value | ||
// from `getSnapshot`. | ||
function useSyncExternalStore$1(subscribe, getSnapshot) { | ||
return getSnapshot(); | ||
} | ||
const canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); | ||
const isServerEnvironment = !canUseDOM; | ||
const shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2; | ||
const useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
var shim = | ||
"undefined" === typeof window || | ||
"undefined" === typeof window.document || | ||
"undefined" === typeof window.document.createElement | ||
? useSyncExternalStore$1 | ||
: useSyncExternalStore$2; | ||
exports.useSyncExternalStore = | ||
void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim; |
@@ -11,159 +11,88 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
} | ||
var React = require('react'); | ||
var shim = require('use-sync-external-store/shim'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
var useSyncExternalStore = shim.useSyncExternalStore; | ||
// for CommonJS interop. | ||
var useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. | ||
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { | ||
// Use this to track the rendered snapshot. | ||
var instRef = useRef(null); | ||
var inst; | ||
if (instRef.current === null) { | ||
inst = { | ||
hasValue: false, | ||
value: null | ||
}; | ||
instRef.current = inst; | ||
} else { | ||
inst = instRef.current; | ||
} | ||
var _useMemo = useMemo(function () { | ||
// Track the memoized state using closure variables that are local to this | ||
// memoized instance of a getSnapshot function. Intentionally not using a | ||
// useRef hook, because that state would be shared across all concurrent | ||
// copies of the hook/component. | ||
var hasMemo = false; | ||
var memoizedSnapshot; | ||
var memoizedSelection; | ||
var memoizedSelector = function (nextSnapshot) { | ||
if (!hasMemo) { | ||
// The first time the hook is called, there is no memoized result. | ||
hasMemo = true; | ||
memoizedSnapshot = nextSnapshot; | ||
var _nextSelection = selector(nextSnapshot); | ||
if (isEqual !== undefined) { | ||
// Even if the selector has changed, the currently rendered selection | ||
// may be equal to the new selection. We should attempt to reuse the | ||
// current value if possible, to preserve downstream memoizations. | ||
if (inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, _nextSelection)) { | ||
memoizedSelection = currentSelection; | ||
"use strict"; | ||
"production" !== process.env.NODE_ENV && | ||
(function () { | ||
function is(x, y) { | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); | ||
var React = require("react"), | ||
shim = require("use-sync-external-store/shim"), | ||
objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useSyncExternalStore = shim.useSyncExternalStore, | ||
useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; | ||
exports.useSyncExternalStoreWithSelector = function ( | ||
subscribe, | ||
getSnapshot, | ||
getServerSnapshot, | ||
selector, | ||
isEqual | ||
) { | ||
var instRef = useRef(null); | ||
if (null === instRef.current) { | ||
var inst = { hasValue: !1, value: null }; | ||
instRef.current = inst; | ||
} else inst = instRef.current; | ||
instRef = useMemo( | ||
function () { | ||
function memoizedSelector(nextSnapshot) { | ||
if (!hasMemo) { | ||
hasMemo = !0; | ||
memoizedSnapshot = nextSnapshot; | ||
nextSnapshot = selector(nextSnapshot); | ||
if (void 0 !== isEqual && inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSnapshot)) | ||
return (memoizedSelection = currentSelection); | ||
} | ||
return (memoizedSelection = nextSnapshot); | ||
} | ||
currentSelection = memoizedSelection; | ||
if (objectIs(memoizedSnapshot, nextSnapshot)) | ||
return currentSelection; | ||
} | ||
var nextSelection = selector(nextSnapshot); | ||
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) | ||
return (memoizedSnapshot = nextSnapshot), currentSelection; | ||
memoizedSnapshot = nextSnapshot; | ||
return (memoizedSelection = nextSelection); | ||
} | ||
} | ||
memoizedSelection = _nextSelection; | ||
return _nextSelection; | ||
} // We may be able to reuse the previous invocation's result. | ||
// We may be able to reuse the previous invocation's result. | ||
var prevSnapshot = memoizedSnapshot; | ||
var prevSelection = memoizedSelection; | ||
if (objectIs(prevSnapshot, nextSnapshot)) { | ||
// The snapshot is the same as last time. Reuse the previous selection. | ||
return prevSelection; | ||
} // The snapshot has changed, so we need to compute a new selection. | ||
// The snapshot has changed, so we need to compute a new selection. | ||
var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
// If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { | ||
return prevSelection; | ||
} | ||
memoizedSnapshot = nextSnapshot; | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
}; // Assigning this to a constant so that Flow knows it can't change. | ||
// Assigning this to a constant so that Flow knows it can't change. | ||
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; | ||
var getSnapshotWithSelector = function () { | ||
return memoizedSelector(getSnapshot()); | ||
var hasMemo = !1, | ||
memoizedSnapshot, | ||
memoizedSelection, | ||
maybeGetServerSnapshot = | ||
void 0 === getServerSnapshot ? null : getServerSnapshot; | ||
return [ | ||
function () { | ||
return memoizedSelector(getSnapshot()); | ||
}, | ||
null === maybeGetServerSnapshot | ||
? void 0 | ||
: function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
} | ||
]; | ||
}, | ||
[getSnapshot, getServerSnapshot, selector, isEqual] | ||
); | ||
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); | ||
useEffect( | ||
function () { | ||
inst.hasValue = !0; | ||
inst.value = value; | ||
}, | ||
[value] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
}; | ||
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
}; | ||
return [getSnapshotWithSelector, getServerSnapshotWithSelector]; | ||
}, [getSnapshot, getServerSnapshot, selector, isEqual]), | ||
getSelection = _useMemo[0], | ||
getServerSelection = _useMemo[1]; | ||
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection); | ||
useEffect(function () { | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
}, [value]); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); | ||
})(); | ||
} |
/** | ||
* @license React | ||
* use-sync-external-store-shim/with-selector.production.min.js | ||
* use-sync-external-store-shim/with-selector.production.js | ||
* | ||
@@ -11,130 +11,76 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
'use strict'; | ||
var React = require('react'); | ||
var shim = require('use-sync-external-store/shim'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
"use strict"; | ||
var React = require("react"), | ||
shim = require("use-sync-external-store/shim"); | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
const objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
const useSyncExternalStore = shim.useSyncExternalStore; | ||
// for CommonJS interop. | ||
const useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. | ||
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { | ||
// Use this to track the rendered snapshot. | ||
const instRef = useRef(null); | ||
let inst; | ||
if (instRef.current === null) { | ||
inst = { | ||
hasValue: false, | ||
value: null | ||
}; | ||
var objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useSyncExternalStore = shim.useSyncExternalStore, | ||
useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; | ||
exports.useSyncExternalStoreWithSelector = function ( | ||
subscribe, | ||
getSnapshot, | ||
getServerSnapshot, | ||
selector, | ||
isEqual | ||
) { | ||
var instRef = useRef(null); | ||
if (null === instRef.current) { | ||
var inst = { hasValue: !1, value: null }; | ||
instRef.current = inst; | ||
} else { | ||
inst = instRef.current; | ||
} | ||
const _useMemo = useMemo(() => { | ||
// Track the memoized state using closure variables that are local to this | ||
// memoized instance of a getSnapshot function. Intentionally not using a | ||
// useRef hook, because that state would be shared across all concurrent | ||
// copies of the hook/component. | ||
let hasMemo = false; | ||
let memoizedSnapshot; | ||
let memoizedSelection; | ||
const memoizedSelector = nextSnapshot => { | ||
if (!hasMemo) { | ||
// The first time the hook is called, there is no memoized result. | ||
hasMemo = true; | ||
memoizedSnapshot = nextSnapshot; | ||
const nextSelection = selector(nextSnapshot); | ||
if (isEqual !== undefined) { | ||
// Even if the selector has changed, the currently rendered selection | ||
// may be equal to the new selection. We should attempt to reuse the | ||
// current value if possible, to preserve downstream memoizations. | ||
if (inst.hasValue) { | ||
const currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSelection)) { | ||
memoizedSelection = currentSelection; | ||
return currentSelection; | ||
} | ||
} else inst = instRef.current; | ||
instRef = useMemo( | ||
function () { | ||
function memoizedSelector(nextSnapshot) { | ||
if (!hasMemo) { | ||
hasMemo = !0; | ||
memoizedSnapshot = nextSnapshot; | ||
nextSnapshot = selector(nextSnapshot); | ||
if (void 0 !== isEqual && inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSnapshot)) | ||
return (memoizedSelection = currentSelection); | ||
} | ||
return (memoizedSelection = nextSnapshot); | ||
} | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
} // We may be able to reuse the previous invocation's result. | ||
// We may be able to reuse the previous invocation's result. | ||
const prevSnapshot = memoizedSnapshot; | ||
const prevSelection = memoizedSelection; | ||
if (objectIs(prevSnapshot, nextSnapshot)) { | ||
// The snapshot is the same as last time. Reuse the previous selection. | ||
return prevSelection; | ||
} // The snapshot has changed, so we need to compute a new selection. | ||
// The snapshot has changed, so we need to compute a new selection. | ||
const nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
// If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { | ||
return prevSelection; | ||
currentSelection = memoizedSelection; | ||
if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection; | ||
var nextSelection = selector(nextSnapshot); | ||
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) | ||
return (memoizedSnapshot = nextSnapshot), currentSelection; | ||
memoizedSnapshot = nextSnapshot; | ||
return (memoizedSelection = nextSelection); | ||
} | ||
memoizedSnapshot = nextSnapshot; | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
}; // Assigning this to a constant so that Flow knows it can't change. | ||
// Assigning this to a constant so that Flow knows it can't change. | ||
const maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; | ||
const getSnapshotWithSelector = () => memoizedSelector(getSnapshot()); | ||
const getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : () => memoizedSelector(maybeGetServerSnapshot()); | ||
return [getSnapshotWithSelector, getServerSnapshotWithSelector]; | ||
}, [getSnapshot, getServerSnapshot, selector, isEqual]), | ||
getSelection = _useMemo[0], | ||
getServerSelection = _useMemo[1]; | ||
const value = useSyncExternalStore(subscribe, getSelection, getServerSelection); | ||
useEffect(() => { | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
}, [value]); | ||
var hasMemo = !1, | ||
memoizedSnapshot, | ||
memoizedSelection, | ||
maybeGetServerSnapshot = | ||
void 0 === getServerSnapshot ? null : getServerSnapshot; | ||
return [ | ||
function () { | ||
return memoizedSelector(getSnapshot()); | ||
}, | ||
null === maybeGetServerSnapshot | ||
? void 0 | ||
: function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
} | ||
]; | ||
}, | ||
[getSnapshot, getServerSnapshot, selector, isEqual] | ||
); | ||
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); | ||
useEffect( | ||
function () { | ||
inst.hasValue = !0; | ||
inst.value = value; | ||
}, | ||
[value] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
}; |
@@ -11,158 +11,87 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
} | ||
var React = require('react'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
} | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
var useSyncExternalStore = React.useSyncExternalStore; | ||
// for CommonJS interop. | ||
var useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. | ||
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { | ||
// Use this to track the rendered snapshot. | ||
var instRef = useRef(null); | ||
var inst; | ||
if (instRef.current === null) { | ||
inst = { | ||
hasValue: false, | ||
value: null | ||
}; | ||
instRef.current = inst; | ||
} else { | ||
inst = instRef.current; | ||
} | ||
var _useMemo = useMemo(function () { | ||
// Track the memoized state using closure variables that are local to this | ||
// memoized instance of a getSnapshot function. Intentionally not using a | ||
// useRef hook, because that state would be shared across all concurrent | ||
// copies of the hook/component. | ||
var hasMemo = false; | ||
var memoizedSnapshot; | ||
var memoizedSelection; | ||
var memoizedSelector = function (nextSnapshot) { | ||
if (!hasMemo) { | ||
// The first time the hook is called, there is no memoized result. | ||
hasMemo = true; | ||
memoizedSnapshot = nextSnapshot; | ||
var _nextSelection = selector(nextSnapshot); | ||
if (isEqual !== undefined) { | ||
// Even if the selector has changed, the currently rendered selection | ||
// may be equal to the new selection. We should attempt to reuse the | ||
// current value if possible, to preserve downstream memoizations. | ||
if (inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, _nextSelection)) { | ||
memoizedSelection = currentSelection; | ||
"use strict"; | ||
"production" !== process.env.NODE_ENV && | ||
(function () { | ||
function is(x, y) { | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); | ||
var React = require("react"), | ||
objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useSyncExternalStore = React.useSyncExternalStore, | ||
useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; | ||
exports.useSyncExternalStoreWithSelector = function ( | ||
subscribe, | ||
getSnapshot, | ||
getServerSnapshot, | ||
selector, | ||
isEqual | ||
) { | ||
var instRef = useRef(null); | ||
if (null === instRef.current) { | ||
var inst = { hasValue: !1, value: null }; | ||
instRef.current = inst; | ||
} else inst = instRef.current; | ||
instRef = useMemo( | ||
function () { | ||
function memoizedSelector(nextSnapshot) { | ||
if (!hasMemo) { | ||
hasMemo = !0; | ||
memoizedSnapshot = nextSnapshot; | ||
nextSnapshot = selector(nextSnapshot); | ||
if (void 0 !== isEqual && inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSnapshot)) | ||
return (memoizedSelection = currentSelection); | ||
} | ||
return (memoizedSelection = nextSnapshot); | ||
} | ||
currentSelection = memoizedSelection; | ||
if (objectIs(memoizedSnapshot, nextSnapshot)) | ||
return currentSelection; | ||
} | ||
var nextSelection = selector(nextSnapshot); | ||
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) | ||
return (memoizedSnapshot = nextSnapshot), currentSelection; | ||
memoizedSnapshot = nextSnapshot; | ||
return (memoizedSelection = nextSelection); | ||
} | ||
} | ||
memoizedSelection = _nextSelection; | ||
return _nextSelection; | ||
} // We may be able to reuse the previous invocation's result. | ||
// We may be able to reuse the previous invocation's result. | ||
var prevSnapshot = memoizedSnapshot; | ||
var prevSelection = memoizedSelection; | ||
if (objectIs(prevSnapshot, nextSnapshot)) { | ||
// The snapshot is the same as last time. Reuse the previous selection. | ||
return prevSelection; | ||
} // The snapshot has changed, so we need to compute a new selection. | ||
// The snapshot has changed, so we need to compute a new selection. | ||
var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
// If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { | ||
return prevSelection; | ||
} | ||
memoizedSnapshot = nextSnapshot; | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
}; // Assigning this to a constant so that Flow knows it can't change. | ||
// Assigning this to a constant so that Flow knows it can't change. | ||
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; | ||
var getSnapshotWithSelector = function () { | ||
return memoizedSelector(getSnapshot()); | ||
var hasMemo = !1, | ||
memoizedSnapshot, | ||
memoizedSelection, | ||
maybeGetServerSnapshot = | ||
void 0 === getServerSnapshot ? null : getServerSnapshot; | ||
return [ | ||
function () { | ||
return memoizedSelector(getSnapshot()); | ||
}, | ||
null === maybeGetServerSnapshot | ||
? void 0 | ||
: function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
} | ||
]; | ||
}, | ||
[getSnapshot, getServerSnapshot, selector, isEqual] | ||
); | ||
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); | ||
useEffect( | ||
function () { | ||
inst.hasValue = !0; | ||
inst.value = value; | ||
}, | ||
[value] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
}; | ||
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
}; | ||
return [getSnapshotWithSelector, getServerSnapshotWithSelector]; | ||
}, [getSnapshot, getServerSnapshot, selector, isEqual]), | ||
getSelection = _useMemo[0], | ||
getServerSelection = _useMemo[1]; | ||
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection); | ||
useEffect(function () { | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
}, [value]); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); | ||
} | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); | ||
})(); | ||
} |
/** | ||
* @license React | ||
* use-sync-external-store-with-selector.production.min.js | ||
* use-sync-external-store-with-selector.production.js | ||
* | ||
@@ -11,129 +11,75 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
'use strict'; | ||
var React = require('react'); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
"use strict"; | ||
var React = require("react"); | ||
function is(x, y) { | ||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare | ||
; | ||
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y); | ||
} | ||
const objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
const useSyncExternalStore = React.useSyncExternalStore; | ||
// for CommonJS interop. | ||
const useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments. | ||
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { | ||
// Use this to track the rendered snapshot. | ||
const instRef = useRef(null); | ||
let inst; | ||
if (instRef.current === null) { | ||
inst = { | ||
hasValue: false, | ||
value: null | ||
}; | ||
var objectIs = "function" === typeof Object.is ? Object.is : is, | ||
useSyncExternalStore = React.useSyncExternalStore, | ||
useRef = React.useRef, | ||
useEffect = React.useEffect, | ||
useMemo = React.useMemo, | ||
useDebugValue = React.useDebugValue; | ||
exports.useSyncExternalStoreWithSelector = function ( | ||
subscribe, | ||
getSnapshot, | ||
getServerSnapshot, | ||
selector, | ||
isEqual | ||
) { | ||
var instRef = useRef(null); | ||
if (null === instRef.current) { | ||
var inst = { hasValue: !1, value: null }; | ||
instRef.current = inst; | ||
} else { | ||
inst = instRef.current; | ||
} | ||
const _useMemo = useMemo(() => { | ||
// Track the memoized state using closure variables that are local to this | ||
// memoized instance of a getSnapshot function. Intentionally not using a | ||
// useRef hook, because that state would be shared across all concurrent | ||
// copies of the hook/component. | ||
let hasMemo = false; | ||
let memoizedSnapshot; | ||
let memoizedSelection; | ||
const memoizedSelector = nextSnapshot => { | ||
if (!hasMemo) { | ||
// The first time the hook is called, there is no memoized result. | ||
hasMemo = true; | ||
memoizedSnapshot = nextSnapshot; | ||
const nextSelection = selector(nextSnapshot); | ||
if (isEqual !== undefined) { | ||
// Even if the selector has changed, the currently rendered selection | ||
// may be equal to the new selection. We should attempt to reuse the | ||
// current value if possible, to preserve downstream memoizations. | ||
if (inst.hasValue) { | ||
const currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSelection)) { | ||
memoizedSelection = currentSelection; | ||
return currentSelection; | ||
} | ||
} else inst = instRef.current; | ||
instRef = useMemo( | ||
function () { | ||
function memoizedSelector(nextSnapshot) { | ||
if (!hasMemo) { | ||
hasMemo = !0; | ||
memoizedSnapshot = nextSnapshot; | ||
nextSnapshot = selector(nextSnapshot); | ||
if (void 0 !== isEqual && inst.hasValue) { | ||
var currentSelection = inst.value; | ||
if (isEqual(currentSelection, nextSnapshot)) | ||
return (memoizedSelection = currentSelection); | ||
} | ||
return (memoizedSelection = nextSnapshot); | ||
} | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
} // We may be able to reuse the previous invocation's result. | ||
// We may be able to reuse the previous invocation's result. | ||
const prevSnapshot = memoizedSnapshot; | ||
const prevSelection = memoizedSelection; | ||
if (objectIs(prevSnapshot, nextSnapshot)) { | ||
// The snapshot is the same as last time. Reuse the previous selection. | ||
return prevSelection; | ||
} // The snapshot has changed, so we need to compute a new selection. | ||
// The snapshot has changed, so we need to compute a new selection. | ||
const nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
// If a custom isEqual function is provided, use that to check if the data | ||
// has changed. If it hasn't, return the previous selection. That signals | ||
// to React that the selections are conceptually equal, and we can bail | ||
// out of rendering. | ||
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) { | ||
return prevSelection; | ||
currentSelection = memoizedSelection; | ||
if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection; | ||
var nextSelection = selector(nextSnapshot); | ||
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) | ||
return (memoizedSnapshot = nextSnapshot), currentSelection; | ||
memoizedSnapshot = nextSnapshot; | ||
return (memoizedSelection = nextSelection); | ||
} | ||
memoizedSnapshot = nextSnapshot; | ||
memoizedSelection = nextSelection; | ||
return nextSelection; | ||
}; // Assigning this to a constant so that Flow knows it can't change. | ||
// Assigning this to a constant so that Flow knows it can't change. | ||
const maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot; | ||
const getSnapshotWithSelector = () => memoizedSelector(getSnapshot()); | ||
const getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : () => memoizedSelector(maybeGetServerSnapshot()); | ||
return [getSnapshotWithSelector, getServerSnapshotWithSelector]; | ||
}, [getSnapshot, getServerSnapshot, selector, isEqual]), | ||
getSelection = _useMemo[0], | ||
getServerSelection = _useMemo[1]; | ||
const value = useSyncExternalStore(subscribe, getSelection, getServerSelection); | ||
useEffect(() => { | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
}, [value]); | ||
var hasMemo = !1, | ||
memoizedSnapshot, | ||
memoizedSelection, | ||
maybeGetServerSnapshot = | ||
void 0 === getServerSnapshot ? null : getServerSnapshot; | ||
return [ | ||
function () { | ||
return memoizedSelector(getSnapshot()); | ||
}, | ||
null === maybeGetServerSnapshot | ||
? void 0 | ||
: function () { | ||
return memoizedSelector(maybeGetServerSnapshot()); | ||
} | ||
]; | ||
}, | ||
[getSnapshot, getServerSnapshot, selector, isEqual] | ||
); | ||
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); | ||
useEffect( | ||
function () { | ||
inst.hasValue = !0; | ||
inst.value = value; | ||
}, | ||
[value] | ||
); | ||
useDebugValue(value); | ||
return value; | ||
} | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
}; |
@@ -11,74 +11,18 @@ /** | ||
'use strict'; | ||
if (process.env.NODE_ENV !== "production") { | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); | ||
"use strict"; | ||
if ("production" !== process.env.NODE_ENV) { | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); | ||
var useSyncExternalStore$jscomp$inline_1 = | ||
require("react").useSyncExternalStore; | ||
console.error( | ||
"The main 'use-sync-external-store' entry point is not supported; all it does is re-export useSyncExternalStore from the 'react' package, so it only works with React 18+.\n\nIf you wish to support React 16 and 17, import from 'use-sync-external-store/shim' instead. It will fall back to a shimmed implementation when the native one is not available.\n\nIf you only support React 18+, you can import directly from 'react'." | ||
); | ||
exports.useSyncExternalStore = useSyncExternalStore$jscomp$inline_1; | ||
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && | ||
"function" === | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); | ||
} | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
function error(format) { | ||
{ | ||
{ | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
printWarning('error', format, args); | ||
} | ||
} | ||
} | ||
function printWarning(level, format, args) { | ||
// When changing this logic, you might want to also | ||
// update consoleWithStackDev.www.js as well. | ||
{ | ||
var stack = ReactSharedInternals.getStackAddendum(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
var argsWithFormat = args.map(function (item) { | ||
return String(item); | ||
}); // Careful: RN currently depends on this prefix | ||
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it | ||
// breaks IE9: https://github.com/facebook/react/issues/13610 | ||
// eslint-disable-next-line react-internal/no-production-logging | ||
Function.prototype.apply.call(console[level], console, argsWithFormat); | ||
} | ||
} | ||
var useSyncExternalStore = React.useSyncExternalStore; | ||
{ | ||
error("The main 'use-sync-external-store' entry point is not supported; all it " + "does is re-export useSyncExternalStore from the 'react' package, so " + 'it only works with React 18+.' + '\n\n' + 'If you wish to support React 16 and 17, import from ' + "'use-sync-external-store/shim' instead. It will fall back to a shimmed " + 'implementation when the native one is not available.' + '\n\n' + "If you only support React 18+, you can import directly from 'react'."); | ||
} | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === | ||
'function' | ||
) { | ||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); | ||
} | ||
})(); | ||
} |
/** | ||
* @license React | ||
* use-sync-external-store.production.min.js | ||
* use-sync-external-store.production.js | ||
* | ||
@@ -11,8 +11,4 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
'use strict'; | ||
var React = require('react'); | ||
const useSyncExternalStore = React.useSyncExternalStore; | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
"use strict"; | ||
var useSyncExternalStore = require("react").useSyncExternalStore; | ||
exports.useSyncExternalStore = useSyncExternalStore; |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/use-sync-external-store.production.min.js'); | ||
module.exports = require('./cjs/use-sync-external-store.production.js'); | ||
} else { | ||
module.exports = require('./cjs/use-sync-external-store.development.js'); | ||
} |
{ | ||
"name": "use-sync-external-store", | ||
"description": "Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.", | ||
"version": "0.0.0-experimental-33a32441e9-20240418", | ||
"version": "0.0.0-experimental-33c7bd9a-20241104", | ||
"repository": { | ||
@@ -22,3 +22,3 @@ "type": "git", | ||
"peerDependencies": { | ||
"react": "0.0.0-experimental-33a32441e9-20240418" | ||
"react": "0.0.0-experimental-33c7bd9a-20241104" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('../cjs/use-sync-external-store-shim.production.min.js'); | ||
module.exports = require('../cjs/use-sync-external-store-shim.production.js'); | ||
} else { | ||
module.exports = require('../cjs/use-sync-external-store-shim.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('../cjs/use-sync-external-store-shim.native.production.min.js'); | ||
module.exports = require('../cjs/use-sync-external-store-shim.native.production.js'); | ||
} else { | ||
module.exports = require('../cjs/use-sync-external-store-shim.native.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('../cjs/use-sync-external-store-shim/with-selector.production.min.js'); | ||
module.exports = require('../cjs/use-sync-external-store-shim/with-selector.production.js'); | ||
} else { | ||
module.exports = require('../cjs/use-sync-external-store-shim/with-selector.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/use-sync-external-store-with-selector.production.min.js'); | ||
module.exports = require('./cjs/use-sync-external-store-with-selector.production.js'); | ||
} else { | ||
module.exports = require('./cjs/use-sync-external-store-with-selector.development.js'); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
2
27668
18
731
1