use-sync-external-store-shim.native.development.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @license React
  3. * use-sync-external-store-shim.native.development.js
  4. *
  5. * Copyright (c) Meta Platforms, Inc. and affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */
  10. "use strict";
  11. "production" !== process.env.NODE_ENV &&
  12. (function () {
  13. function is(x, y) {
  14. return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
  15. }
  16. function useSyncExternalStore$1(subscribe, getSnapshot) {
  17. didWarnOld18Alpha ||
  18. void 0 === React.startTransition ||
  19. ((didWarnOld18Alpha = !0),
  20. console.error(
  21. "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."
  22. ));
  23. var value = getSnapshot();
  24. if (!didWarnUncachedGetSnapshot) {
  25. var cachedValue = getSnapshot();
  26. objectIs(value, cachedValue) ||
  27. (console.error(
  28. "The result of getSnapshot should be cached to avoid an infinite loop"
  29. ),
  30. (didWarnUncachedGetSnapshot = !0));
  31. }
  32. cachedValue = useState({
  33. inst: { value: value, getSnapshot: getSnapshot }
  34. });
  35. var inst = cachedValue[0].inst,
  36. forceUpdate = cachedValue[1];
  37. useLayoutEffect(
  38. function () {
  39. inst.value = value;
  40. inst.getSnapshot = getSnapshot;
  41. checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
  42. },
  43. [subscribe, value, getSnapshot]
  44. );
  45. useEffect(
  46. function () {
  47. checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
  48. return subscribe(function () {
  49. checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
  50. });
  51. },
  52. [subscribe]
  53. );
  54. useDebugValue(value);
  55. return value;
  56. }
  57. function checkIfSnapshotChanged(inst) {
  58. var latestGetSnapshot = inst.getSnapshot;
  59. inst = inst.value;
  60. try {
  61. var nextValue = latestGetSnapshot();
  62. return !objectIs(inst, nextValue);
  63. } catch (error) {
  64. return !0;
  65. }
  66. }
  67. "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
  68. "function" ===
  69. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
  70. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
  71. var React = require("react"),
  72. objectIs = "function" === typeof Object.is ? Object.is : is,
  73. useState = React.useState,
  74. useEffect = React.useEffect,
  75. useLayoutEffect = React.useLayoutEffect,
  76. useDebugValue = React.useDebugValue,
  77. didWarnOld18Alpha = !1,
  78. didWarnUncachedGetSnapshot = !1;
  79. exports.useSyncExternalStore =
  80. void 0 !== React.useSyncExternalStore
  81. ? React.useSyncExternalStore
  82. : useSyncExternalStore$1;
  83. "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
  84. "function" ===
  85. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
  86. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
  87. })();