use-sync-external-store
Advanced tools
Comparing version 0.0.0-experimental-9d4e8e84f-20220207 to 0.0.0-experimental-9d4fba0788-20240530
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,5 +25,5 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var React = require('react'); | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
@@ -43,4 +40,6 @@ function error(format) { | ||
} | ||
} | ||
} // eslint-disable-next-line react-internal/no-production-logging | ||
var supportsCreateTask = !!console.createTask; | ||
function printWarning(level, format, args) { | ||
@@ -50,20 +49,35 @@ // When changing this logic, you might want to also | ||
{ | ||
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; | ||
var stack = ReactDebugCurrentFrame.getStackAddendum(); | ||
var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n'; | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
if (!supportsCreateTask && ReactSharedInternals.getCurrentStack) { | ||
// We only add the current stack to the console when createTask is not supported. | ||
// Since createTask requires DevTools to be open to work, this means that stacks | ||
// can be lost while DevTools isn't open but we can't detect this. | ||
var stack = ReactSharedInternals.getCurrentStack(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} | ||
} | ||
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 | ||
if (isErrorLogger) { | ||
// Don't prefix our default logging formatting in ReactFiberErrorLoggger. | ||
// Don't toString the arguments. | ||
args.unshift(format); | ||
} else { | ||
// TODO: Remove this prefix and stop toStringing in the wrapper and | ||
// instead do it at each callsite as needed. | ||
// Careful: RN currently depends on this prefix | ||
// eslint-disable-next-line react-internal/safe-string-coercion | ||
args = args.map(function (item) { | ||
return String(item); | ||
}); | ||
args.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); | ||
Function.prototype.apply.call(console[level], console, args); | ||
} | ||
@@ -81,3 +95,4 @@ } | ||
var objectIs = typeof Object.is === 'function' ? Object.is : is; | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
@@ -102,3 +117,3 @@ // dispatch for CommonJS interop named imports. | ||
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
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 | ||
@@ -126,3 +141,5 @@ // will need to track that themselves and return the correct value | ||
if (!didWarnUncachedGetSnapshot) { | ||
if (value !== getSnapshot()) { | ||
var cachedValue = getSnapshot(); | ||
if (!objectIs(value, cachedValue)) { | ||
error('The result of getSnapshot should be cached to avoid an infinite loop'); | ||
@@ -231,7 +248,6 @@ | ||
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore; | ||
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2; | ||
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore$2; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
if ( | ||
@@ -244,4 +260,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,5 +25,5 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var React = require('react'); | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
@@ -43,4 +40,6 @@ function error(format) { | ||
} | ||
} | ||
} // eslint-disable-next-line react-internal/no-production-logging | ||
var supportsCreateTask = !!console.createTask; | ||
function printWarning(level, format, args) { | ||
@@ -50,20 +49,35 @@ // When changing this logic, you might want to also | ||
{ | ||
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; | ||
var stack = ReactDebugCurrentFrame.getStackAddendum(); | ||
var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n'; | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
if (!supportsCreateTask && ReactSharedInternals.getCurrentStack) { | ||
// We only add the current stack to the console when createTask is not supported. | ||
// Since createTask requires DevTools to be open to work, this means that stacks | ||
// can be lost while DevTools isn't open but we can't detect this. | ||
var stack = ReactSharedInternals.getCurrentStack(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} | ||
} | ||
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 | ||
if (isErrorLogger) { | ||
// Don't prefix our default logging formatting in ReactFiberErrorLoggger. | ||
// Don't toString the arguments. | ||
args.unshift(format); | ||
} else { | ||
// TODO: Remove this prefix and stop toStringing in the wrapper and | ||
// instead do it at each callsite as needed. | ||
// Careful: RN currently depends on this prefix | ||
// eslint-disable-next-line react-internal/safe-string-coercion | ||
args = args.map(function (item) { | ||
return String(item); | ||
}); | ||
args.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); | ||
Function.prototype.apply.call(console[level], console, args); | ||
} | ||
@@ -81,3 +95,4 @@ } | ||
var objectIs = typeof Object.is === 'function' ? Object.is : is; | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
@@ -102,3 +117,3 @@ // dispatch for CommonJS interop named imports. | ||
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of | ||
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 | ||
@@ -126,3 +141,5 @@ // will need to track that themselves and return the correct value | ||
if (!didWarnUncachedGetSnapshot) { | ||
if (value !== getSnapshot()) { | ||
var cachedValue = getSnapshot(); | ||
if (!objectIs(value, cachedValue)) { | ||
error('The result of getSnapshot should be cached to avoid an infinite loop'); | ||
@@ -219,7 +236,6 @@ | ||
var shim = useSyncExternalStore; | ||
var useSyncExternalStore$1 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
var shim = useSyncExternalStore$1; | ||
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; | ||
exports.useSyncExternalStore = useSyncExternalStore$1; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
exports.useSyncExternalStore = useSyncExternalStore; | ||
if ( | ||
@@ -232,4 +248,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,3 +25,3 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var React = require('react'); | ||
var React = require('react'); | ||
var shim = require('use-sync-external-store/shim'); | ||
@@ -41,3 +38,4 @@ | ||
var objectIs = typeof Object.is === 'function' ? Object.is : is; | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
@@ -151,3 +149,5 @@ var useSyncExternalStore = shim.useSyncExternalStore; | ||
useEffect(function () { | ||
inst.hasValue = true; | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
@@ -160,3 +160,2 @@ }, [value]); | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
@@ -169,4 +168,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,3 +25,3 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var React = require('react'); | ||
var React = require('react'); | ||
@@ -40,3 +37,4 @@ /** | ||
var objectIs = typeof Object.is === 'function' ? Object.is : is; | ||
var objectIs = // $FlowFixMe[method-unbinding] | ||
typeof Object.is === 'function' ? Object.is : is; | ||
@@ -150,3 +148,5 @@ var useSyncExternalStore = React.useSyncExternalStore; | ||
useEffect(function () { | ||
inst.hasValue = true; | ||
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported | ||
inst.hasValue = true; // $FlowFixMe[incompatible-type] | ||
inst.value = value; | ||
@@ -159,3 +159,2 @@ }, [value]); | ||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
@@ -168,4 +167,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,5 +25,5 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var React = require('react'); | ||
var React = require('react'); | ||
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; | ||
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; | ||
@@ -43,4 +40,6 @@ function error(format) { | ||
} | ||
} | ||
} // eslint-disable-next-line react-internal/no-production-logging | ||
var supportsCreateTask = !!console.createTask; | ||
function printWarning(level, format, args) { | ||
@@ -50,20 +49,35 @@ // When changing this logic, you might want to also | ||
{ | ||
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; | ||
var stack = ReactDebugCurrentFrame.getStackAddendum(); | ||
var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n'; | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} // eslint-disable-next-line react-internal/safe-string-coercion | ||
if (!supportsCreateTask && ReactSharedInternals.getCurrentStack) { | ||
// We only add the current stack to the console when createTask is not supported. | ||
// Since createTask requires DevTools to be open to work, this means that stacks | ||
// can be lost while DevTools isn't open but we can't detect this. | ||
var stack = ReactSharedInternals.getCurrentStack(); | ||
if (stack !== '') { | ||
format += '%s'; | ||
args = args.concat([stack]); | ||
} | ||
} | ||
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 | ||
if (isErrorLogger) { | ||
// Don't prefix our default logging formatting in ReactFiberErrorLoggger. | ||
// Don't toString the arguments. | ||
args.unshift(format); | ||
} else { | ||
// TODO: Remove this prefix and stop toStringing in the wrapper and | ||
// instead do it at each callsite as needed. | ||
// Careful: RN currently depends on this prefix | ||
// eslint-disable-next-line react-internal/safe-string-coercion | ||
args = args.map(function (item) { | ||
return String(item); | ||
}); | ||
args.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); | ||
Function.prototype.apply.call(console[level], console, args); | ||
} | ||
@@ -75,7 +89,6 @@ } | ||
{ | ||
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'."); | ||
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 ( | ||
@@ -88,4 +101,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
'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-9d4e8e84f-20220207", | ||
"version": "0.0.0-experimental-9d4fba0788-20240530", | ||
"repository": { | ||
@@ -13,3 +13,2 @@ "type": "git", | ||
"README.md", | ||
"build-info.json", | ||
"index.js", | ||
@@ -24,4 +23,8 @@ "index.native.js", | ||
"peerDependencies": { | ||
"react": "0.0.0-experimental-9d4e8e84f-20220207" | ||
"react": "0.0.0-experimental-9d4fba0788-20240530" | ||
}, | ||
"devDependencies": { | ||
"react-17": "npm:react@^17", | ||
"react-dom-17": "npm:react-dom@^17" | ||
} | ||
} |
# use-sync-external-store | ||
Backwards compatible shim for React's `useSyncExternalStore`. Works with any React that supports hooks. | ||
Backwards-compatible shim for [`React.useSyncExternalStore`](https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore). Works with any React that supports Hooks. | ||
Until `useSyncExternalStore` is documented, refer to https://github.com/reactwg/react-18/discussions/86 | ||
See also https://github.com/reactwg/react-18/discussions/86. |
'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'); | ||
} |
Sorry, the diff of this file is not supported yet
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
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
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
45065
1100
2
0
2