use-sync-external-store 1.4.0-rc.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,157 +8,90 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
 
11
- 'use strict';
12
-
13
- if (process.env.NODE_ENV !== "production") {
14
- (function() {
15
- 'use strict';
16
- if (
17
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
18
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
19
- 'function'
20
- ) {
21
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
22
- }
23
- var React = require('react');
24
- var shim = require('use-sync-external-store/shim');
25
-
26
- /**
27
- * inlined Object.is polyfill to avoid requiring consumers ship their own
28
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
29
- */
30
- function is(x, y) {
31
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
32
- ;
33
- }
34
-
35
- var objectIs = // $FlowFixMe[method-unbinding]
36
- typeof Object.is === 'function' ? Object.is : is;
37
-
38
- var useSyncExternalStore = shim.useSyncExternalStore;
39
-
40
- // for CommonJS interop.
41
-
42
- var useRef = React.useRef,
43
- useEffect = React.useEffect,
44
- useMemo = React.useMemo,
45
- useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
46
-
47
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
48
- // Use this to track the rendered snapshot.
49
- var instRef = useRef(null);
50
- var inst;
51
-
52
- if (instRef.current === null) {
53
- inst = {
54
- hasValue: false,
55
- value: null
56
- };
57
- instRef.current = inst;
58
- } else {
59
- inst = instRef.current;
60
- }
61
-
62
- var _useMemo = useMemo(function () {
63
- // Track the memoized state using closure variables that are local to this
64
- // memoized instance of a getSnapshot function. Intentionally not using a
65
- // useRef hook, because that state would be shared across all concurrent
66
- // copies of the hook/component.
67
- var hasMemo = false;
68
- var memoizedSnapshot;
69
- var memoizedSelection;
70
-
71
- var memoizedSelector = function (nextSnapshot) {
72
- if (!hasMemo) {
73
- // The first time the hook is called, there is no memoized result.
74
- hasMemo = true;
75
- memoizedSnapshot = nextSnapshot;
76
-
77
- var _nextSelection = selector(nextSnapshot);
78
-
79
- if (isEqual !== undefined) {
80
- // Even if the selector has changed, the currently rendered selection
81
- // may be equal to the new selection. We should attempt to reuse the
82
- // current value if possible, to preserve downstream memoizations.
83
- if (inst.hasValue) {
84
- var currentSelection = inst.value;
85
-
86
- if (isEqual(currentSelection, _nextSelection)) {
87
- memoizedSelection = currentSelection;
88
- return currentSelection;
11
+ "use strict";
12
+ "production" !== process.env.NODE_ENV &&
13
+ (function () {
14
+ function is(x, y) {
15
+ return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
16
+ }
17
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
18
+ "function" ===
19
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
20
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
21
+ var React = require("react"),
22
+ shim = require("use-sync-external-store/shim"),
23
+ objectIs = "function" === typeof Object.is ? Object.is : is,
24
+ useSyncExternalStore = shim.useSyncExternalStore,
25
+ useRef = React.useRef,
26
+ useEffect = React.useEffect,
27
+ useMemo = React.useMemo,
28
+ useDebugValue = React.useDebugValue;
29
+ exports.useSyncExternalStoreWithSelector = function (
30
+ subscribe,
31
+ getSnapshot,
32
+ getServerSnapshot,
33
+ selector,
34
+ isEqual
35
+ ) {
36
+ var instRef = useRef(null);
37
+ if (null === instRef.current) {
38
+ var inst = { hasValue: !1, value: null };
39
+ instRef.current = inst;
40
+ } else inst = instRef.current;
41
+ instRef = useMemo(
42
+ function () {
43
+ function memoizedSelector(nextSnapshot) {
44
+ if (!hasMemo) {
45
+ hasMemo = !0;
46
+ memoizedSnapshot = nextSnapshot;
47
+ nextSnapshot = selector(nextSnapshot);
48
+ if (void 0 !== isEqual && inst.hasValue) {
49
+ var currentSelection = inst.value;
50
+ if (isEqual(currentSelection, nextSnapshot))
51
+ return (memoizedSelection = currentSelection);
52
+ }
53
+ return (memoizedSelection = nextSnapshot);
89
54
  }
55
+ currentSelection = memoizedSelection;
56
+ if (objectIs(memoizedSnapshot, nextSnapshot))
57
+ return currentSelection;
58
+ var nextSelection = selector(nextSnapshot);
59
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
60
+ return (memoizedSnapshot = nextSnapshot), currentSelection;
61
+ memoizedSnapshot = nextSnapshot;
62
+ return (memoizedSelection = nextSelection);
90
63
  }
91
- }
92
-
93
- memoizedSelection = _nextSelection;
94
- return _nextSelection;
95
- } // We may be able to reuse the previous invocation's result.
96
-
97
-
98
- // We may be able to reuse the previous invocation's result.
99
- var prevSnapshot = memoizedSnapshot;
100
- var prevSelection = memoizedSelection;
101
-
102
- if (objectIs(prevSnapshot, nextSnapshot)) {
103
- // The snapshot is the same as last time. Reuse the previous selection.
104
- return prevSelection;
105
- } // The snapshot has changed, so we need to compute a new selection.
106
-
107
-
108
- // The snapshot has changed, so we need to compute a new selection.
109
- var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
110
- // has changed. If it hasn't, return the previous selection. That signals
111
- // to React that the selections are conceptually equal, and we can bail
112
- // out of rendering.
113
-
114
- // If a custom isEqual function is provided, use that to check if the data
115
- // has changed. If it hasn't, return the previous selection. That signals
116
- // to React that the selections are conceptually equal, and we can bail
117
- // out of rendering.
118
- if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
119
- return prevSelection;
120
- }
121
-
122
- memoizedSnapshot = nextSnapshot;
123
- memoizedSelection = nextSelection;
124
- return nextSelection;
125
- }; // Assigning this to a constant so that Flow knows it can't change.
126
-
127
-
128
- // Assigning this to a constant so that Flow knows it can't change.
129
- var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
130
-
131
- var getSnapshotWithSelector = function () {
132
- return memoizedSelector(getSnapshot());
133
- };
134
-
135
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
136
- return memoizedSelector(maybeGetServerSnapshot());
64
+ var hasMemo = !1,
65
+ memoizedSnapshot,
66
+ memoizedSelection,
67
+ maybeGetServerSnapshot =
68
+ void 0 === getServerSnapshot ? null : getServerSnapshot;
69
+ return [
70
+ function () {
71
+ return memoizedSelector(getSnapshot());
72
+ },
73
+ null === maybeGetServerSnapshot
74
+ ? void 0
75
+ : function () {
76
+ return memoizedSelector(maybeGetServerSnapshot());
77
+ }
78
+ ];
79
+ },
80
+ [getSnapshot, getServerSnapshot, selector, isEqual]
81
+ );
82
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
83
+ useEffect(
84
+ function () {
85
+ inst.hasValue = !0;
86
+ inst.value = value;
87
+ },
88
+ [value]
89
+ );
90
+ useDebugValue(value);
91
+ return value;
137
92
  };
138
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
139
- }, [getSnapshot, getServerSnapshot, selector, isEqual]),
140
- getSelection = _useMemo[0],
141
- getServerSelection = _useMemo[1];
142
-
143
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
144
- useEffect(function () {
145
- // $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported
146
- inst.hasValue = true; // $FlowFixMe[incompatible-type]
147
-
148
- inst.value = value;
149
- }, [value]);
150
- useDebugValue(value);
151
- return value;
152
- }
153
-
154
- exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
155
- if (
156
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
157
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
158
- 'function'
159
- ) {
160
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
161
- }
162
-
93
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
94
+ "function" ===
95
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
96
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
163
97
  })();
164
- }
@@ -50,7 +50,7 @@ exports.useSyncExternalStoreWithSelector = function (
50
50
  if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
51
51
  var nextSelection = selector(nextSnapshot);
52
52
  if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
53
- return currentSelection;
53
+ return (memoizedSnapshot = nextSnapshot), currentSelection;
54
54
  memoizedSnapshot = nextSnapshot;
55
55
  return (memoizedSelection = nextSelection);
56
56
  }
@@ -8,244 +8,88 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
 
11
- 'use strict';
12
-
13
- if (process.env.NODE_ENV !== "production") {
14
- (function() {
15
- 'use strict';
16
- if (
17
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
18
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
19
- 'function'
20
- ) {
21
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
22
- }
23
- var React = require('react');
24
-
25
- var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
26
-
27
- function error(format) {
28
- {
29
- {
30
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
31
- args[_key2 - 1] = arguments[_key2];
32
- }
33
-
34
- printWarning('error', format, args);
11
+ "use strict";
12
+ "production" !== process.env.NODE_ENV &&
13
+ (function () {
14
+ function is(x, y) {
15
+ return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
35
16
  }
36
- }
37
- } // eslint-disable-next-line react-internal/no-production-logging
38
-
39
- function printWarning(level, format, args) {
40
- // When changing this logic, you might want to also
41
- // update consoleWithStackDev.www.js as well.
42
- {
43
- var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
44
-
45
- if (ReactSharedInternals.getCurrentStack) {
46
- // We only add the current stack to the console when createTask is not supported.
47
- // Since createTask requires DevTools to be open to work, this means that stacks
48
- // can be lost while DevTools isn't open but we can't detect this.
49
- var stack = ReactSharedInternals.getCurrentStack();
50
-
51
- if (stack !== '') {
52
- format += '%s';
53
- args = args.concat([stack]);
17
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
18
+ didWarnOld18Alpha ||
19
+ void 0 === React.startTransition ||
20
+ ((didWarnOld18Alpha = !0),
21
+ console.error(
22
+ "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."
23
+ ));
24
+ var value = getSnapshot();
25
+ if (!didWarnUncachedGetSnapshot) {
26
+ var cachedValue = getSnapshot();
27
+ objectIs(value, cachedValue) ||
28
+ (console.error(
29
+ "The result of getSnapshot should be cached to avoid an infinite loop"
30
+ ),
31
+ (didWarnUncachedGetSnapshot = !0));
54
32
  }
55
- }
56
-
57
- if (isErrorLogger) {
58
- // Don't prefix our default logging formatting in ReactFiberErrorLoggger.
59
- // Don't toString the arguments.
60
- args.unshift(format);
61
- } else {
62
- // TODO: Remove this prefix and stop toStringing in the wrapper and
63
- // instead do it at each callsite as needed.
64
- // Careful: RN currently depends on this prefix
65
- // eslint-disable-next-line react-internal/safe-string-coercion
66
- args = args.map(function (item) {
67
- return String(item);
33
+ cachedValue = useState({
34
+ inst: { value: value, getSnapshot: getSnapshot }
68
35
  });
69
- args.unshift('Warning: ' + format);
70
- } // We intentionally don't use spread (or .apply) directly because it
71
- // breaks IE9: https://github.com/facebook/react/issues/13610
72
- // eslint-disable-next-line react-internal/no-production-logging
73
-
74
-
75
- Function.prototype.apply.call(console[level], console, args);
76
- }
77
- }
78
-
79
- /**
80
- * inlined Object.is polyfill to avoid requiring consumers ship their own
81
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
82
- */
83
- function is(x, y) {
84
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
85
- ;
86
- }
87
-
88
- var objectIs = // $FlowFixMe[method-unbinding]
89
- typeof Object.is === 'function' ? Object.is : is;
90
-
91
- // dispatch for CommonJS interop named imports.
92
-
93
- var useState = React.useState,
94
- useEffect = React.useEffect,
95
- useLayoutEffect = React.useLayoutEffect,
96
- useDebugValue = React.useDebugValue;
97
- var didWarnOld18Alpha = false;
98
- var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
99
- // because of a very particular set of implementation details and assumptions
100
- // -- change any one of them and it will break. The most important assumption
101
- // is that updates are always synchronous, because concurrent rendering is
102
- // only available in versions of React that also have a built-in
103
- // useSyncExternalStore API. And we only use this shim when the built-in API
104
- // does not exist.
105
- //
106
- // Do not assume that the clever hacks used by this hook also work in general.
107
- // The point of this shim is to replace the need for hacks by other libraries.
108
-
109
- function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
110
- // React do not expose a way to check if we're hydrating. So users of the shim
111
- // will need to track that themselves and return the correct value
112
- // from `getSnapshot`.
113
- getServerSnapshot) {
114
- {
115
- if (!didWarnOld18Alpha) {
116
- if (React.startTransition !== undefined) {
117
- didWarnOld18Alpha = true;
118
-
119
- 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.');
120
- }
36
+ var inst = cachedValue[0].inst,
37
+ forceUpdate = cachedValue[1];
38
+ useLayoutEffect(
39
+ function () {
40
+ inst.value = value;
41
+ inst.getSnapshot = getSnapshot;
42
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
43
+ },
44
+ [subscribe, value, getSnapshot]
45
+ );
46
+ useEffect(
47
+ function () {
48
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
49
+ return subscribe(function () {
50
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
51
+ });
52
+ },
53
+ [subscribe]
54
+ );
55
+ useDebugValue(value);
56
+ return value;
121
57
  }
122
- } // Read the current snapshot from the store on every render. Again, this
123
- // breaks the rules of React, and only works here because of specific
124
- // implementation details, most importantly that updates are
125
- // always synchronous.
126
-
127
-
128
- var value = getSnapshot();
129
-
130
- {
131
- if (!didWarnUncachedGetSnapshot) {
132
- var cachedValue = getSnapshot();
133
-
134
- if (!objectIs(value, cachedValue)) {
135
- error('The result of getSnapshot should be cached to avoid an infinite loop');
136
-
137
- didWarnUncachedGetSnapshot = true;
58
+ function checkIfSnapshotChanged(inst) {
59
+ var latestGetSnapshot = inst.getSnapshot;
60
+ inst = inst.value;
61
+ try {
62
+ var nextValue = latestGetSnapshot();
63
+ return !objectIs(inst, nextValue);
64
+ } catch (error) {
65
+ return !0;
138
66
  }
139
67
  }
140
- } // Because updates are synchronous, we don't queue them. Instead we force a
141
- // re-render whenever the subscribed state changes by updating an some
142
- // arbitrary useState hook. Then, during render, we call getSnapshot to read
143
- // the current value.
144
- //
145
- // Because we don't actually use the state returned by the useState hook, we
146
- // can save a bit of memory by storing other stuff in that slot.
147
- //
148
- // To implement the early bailout, we need to track some things on a mutable
149
- // object. Usually, we would put that in a useRef hook, but we can stash it in
150
- // our useState hook instead.
151
- //
152
- // To force a re-render, we call forceUpdate({inst}). That works because the
153
- // new object always fails an equality check.
154
-
155
-
156
- var _useState = useState({
157
- inst: {
158
- value: value,
159
- getSnapshot: getSnapshot
160
- }
161
- }),
162
- inst = _useState[0].inst,
163
- forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
164
- // in the layout phase so we can access it during the tearing check that
165
- // happens on subscribe.
166
-
167
-
168
- useLayoutEffect(function () {
169
- inst.value = value;
170
- inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
171
- // commit phase if there was an interleaved mutation. In concurrent mode
172
- // this can happen all the time, but even in synchronous mode, an earlier
173
- // effect may have mutated the store.
174
-
175
- if (checkIfSnapshotChanged(inst)) {
176
- // Force a re-render.
177
- forceUpdate({
178
- inst: inst
179
- });
180
- }
181
- }, [subscribe, value, getSnapshot]);
182
- useEffect(function () {
183
- // Check for changes right before subscribing. Subsequent changes will be
184
- // detected in the subscription handler.
185
- if (checkIfSnapshotChanged(inst)) {
186
- // Force a re-render.
187
- forceUpdate({
188
- inst: inst
189
- });
68
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
69
+ return getSnapshot();
190
70
  }
191
-
192
- var handleStoreChange = function () {
193
- // TODO: Because there is no cross-renderer API for batching updates, it's
194
- // up to the consumer of this library to wrap their subscription event
195
- // with unstable_batchedUpdates. Should we try to detect when this isn't
196
- // the case and print a warning in development?
197
- // The store changed. Check if the snapshot changed since the last time we
198
- // read from the store.
199
- if (checkIfSnapshotChanged(inst)) {
200
- // Force a re-render.
201
- forceUpdate({
202
- inst: inst
203
- });
204
- }
205
- }; // Subscribe to the store and return a clean-up function.
206
-
207
-
208
- return subscribe(handleStoreChange);
209
- }, [subscribe]);
210
- useDebugValue(value);
211
- return value;
212
- }
213
-
214
- function checkIfSnapshotChanged(inst) {
215
- var latestGetSnapshot = inst.getSnapshot;
216
- var prevValue = inst.value;
217
-
218
- try {
219
- var nextValue = latestGetSnapshot();
220
- return !objectIs(prevValue, nextValue);
221
- } catch (error) {
222
- return true;
223
- }
224
- }
225
-
226
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
227
- // Note: The shim does not use getServerSnapshot, because pre-18 versions of
228
- // React do not expose a way to check if we're hydrating. So users of the shim
229
- // will need to track that themselves and return the correct value
230
- // from `getSnapshot`.
231
- return getSnapshot();
232
- }
233
-
234
- var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
235
-
236
- var isServerEnvironment = !canUseDOM;
237
-
238
- var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2;
239
- var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
240
-
241
- exports.useSyncExternalStore = useSyncExternalStore;
242
- if (
243
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
244
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
245
- 'function'
246
- ) {
247
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
248
- }
249
-
71
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
72
+ "function" ===
73
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
74
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
75
+ var React = require("react"),
76
+ objectIs = "function" === typeof Object.is ? Object.is : is,
77
+ useState = React.useState,
78
+ useEffect = React.useEffect,
79
+ useLayoutEffect = React.useLayoutEffect,
80
+ useDebugValue = React.useDebugValue,
81
+ didWarnOld18Alpha = !1,
82
+ didWarnUncachedGetSnapshot = !1,
83
+ shim =
84
+ "undefined" === typeof window ||
85
+ "undefined" === typeof window.document ||
86
+ "undefined" === typeof window.document.createElement
87
+ ? useSyncExternalStore$1
88
+ : useSyncExternalStore$2;
89
+ exports.useSyncExternalStore =
90
+ void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim;
91
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
92
+ "function" ===
93
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
94
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
250
95
  })();
251
- }
@@ -8,232 +8,81 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
 
11
- 'use strict';
12
-
13
- if (process.env.NODE_ENV !== "production") {
14
- (function() {
15
- 'use strict';
16
- if (
17
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
18
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
19
- 'function'
20
- ) {
21
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
22
- }
23
- var React = require('react');
24
-
25
- var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
26
-
27
- function error(format) {
28
- {
29
- {
30
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
31
- args[_key2 - 1] = arguments[_key2];
32
- }
33
-
34
- printWarning('error', format, args);
11
+ "use strict";
12
+ "production" !== process.env.NODE_ENV &&
13
+ (function () {
14
+ function is(x, y) {
15
+ return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
35
16
  }
36
- }
37
- } // eslint-disable-next-line react-internal/no-production-logging
38
-
39
- function printWarning(level, format, args) {
40
- // When changing this logic, you might want to also
41
- // update consoleWithStackDev.www.js as well.
42
- {
43
- var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
44
-
45
- if (ReactSharedInternals.getCurrentStack) {
46
- // We only add the current stack to the console when createTask is not supported.
47
- // Since createTask requires DevTools to be open to work, this means that stacks
48
- // can be lost while DevTools isn't open but we can't detect this.
49
- var stack = ReactSharedInternals.getCurrentStack();
50
-
51
- if (stack !== '') {
52
- format += '%s';
53
- args = args.concat([stack]);
17
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
18
+ didWarnOld18Alpha ||
19
+ void 0 === React.startTransition ||
20
+ ((didWarnOld18Alpha = !0),
21
+ console.error(
22
+ "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."
23
+ ));
24
+ var value = getSnapshot();
25
+ if (!didWarnUncachedGetSnapshot) {
26
+ var cachedValue = getSnapshot();
27
+ objectIs(value, cachedValue) ||
28
+ (console.error(
29
+ "The result of getSnapshot should be cached to avoid an infinite loop"
30
+ ),
31
+ (didWarnUncachedGetSnapshot = !0));
54
32
  }
55
- }
56
-
57
- if (isErrorLogger) {
58
- // Don't prefix our default logging formatting in ReactFiberErrorLoggger.
59
- // Don't toString the arguments.
60
- args.unshift(format);
61
- } else {
62
- // TODO: Remove this prefix and stop toStringing in the wrapper and
63
- // instead do it at each callsite as needed.
64
- // Careful: RN currently depends on this prefix
65
- // eslint-disable-next-line react-internal/safe-string-coercion
66
- args = args.map(function (item) {
67
- return String(item);
33
+ cachedValue = useState({
34
+ inst: { value: value, getSnapshot: getSnapshot }
68
35
  });
69
- args.unshift('Warning: ' + format);
70
- } // We intentionally don't use spread (or .apply) directly because it
71
- // breaks IE9: https://github.com/facebook/react/issues/13610
72
- // eslint-disable-next-line react-internal/no-production-logging
73
-
74
-
75
- Function.prototype.apply.call(console[level], console, args);
76
- }
77
- }
78
-
79
- /**
80
- * inlined Object.is polyfill to avoid requiring consumers ship their own
81
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
82
- */
83
- function is(x, y) {
84
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
85
- ;
86
- }
87
-
88
- var objectIs = // $FlowFixMe[method-unbinding]
89
- typeof Object.is === 'function' ? Object.is : is;
90
-
91
- // dispatch for CommonJS interop named imports.
92
-
93
- var useState = React.useState,
94
- useEffect = React.useEffect,
95
- useLayoutEffect = React.useLayoutEffect,
96
- useDebugValue = React.useDebugValue;
97
- var didWarnOld18Alpha = false;
98
- var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
99
- // because of a very particular set of implementation details and assumptions
100
- // -- change any one of them and it will break. The most important assumption
101
- // is that updates are always synchronous, because concurrent rendering is
102
- // only available in versions of React that also have a built-in
103
- // useSyncExternalStore API. And we only use this shim when the built-in API
104
- // does not exist.
105
- //
106
- // Do not assume that the clever hacks used by this hook also work in general.
107
- // The point of this shim is to replace the need for hacks by other libraries.
108
-
109
- function useSyncExternalStore$1(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
110
- // React do not expose a way to check if we're hydrating. So users of the shim
111
- // will need to track that themselves and return the correct value
112
- // from `getSnapshot`.
113
- getServerSnapshot) {
114
- {
115
- if (!didWarnOld18Alpha) {
116
- if (React.startTransition !== undefined) {
117
- didWarnOld18Alpha = true;
118
-
119
- 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.');
120
- }
36
+ var inst = cachedValue[0].inst,
37
+ forceUpdate = cachedValue[1];
38
+ useLayoutEffect(
39
+ function () {
40
+ inst.value = value;
41
+ inst.getSnapshot = getSnapshot;
42
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
43
+ },
44
+ [subscribe, value, getSnapshot]
45
+ );
46
+ useEffect(
47
+ function () {
48
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
49
+ return subscribe(function () {
50
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
51
+ });
52
+ },
53
+ [subscribe]
54
+ );
55
+ useDebugValue(value);
56
+ return value;
121
57
  }
122
- } // Read the current snapshot from the store on every render. Again, this
123
- // breaks the rules of React, and only works here because of specific
124
- // implementation details, most importantly that updates are
125
- // always synchronous.
126
-
127
-
128
- var value = getSnapshot();
129
-
130
- {
131
- if (!didWarnUncachedGetSnapshot) {
132
- var cachedValue = getSnapshot();
133
-
134
- if (!objectIs(value, cachedValue)) {
135
- error('The result of getSnapshot should be cached to avoid an infinite loop');
136
-
137
- didWarnUncachedGetSnapshot = true;
58
+ function checkIfSnapshotChanged(inst) {
59
+ var latestGetSnapshot = inst.getSnapshot;
60
+ inst = inst.value;
61
+ try {
62
+ var nextValue = latestGetSnapshot();
63
+ return !objectIs(inst, nextValue);
64
+ } catch (error) {
65
+ return !0;
138
66
  }
139
67
  }
140
- } // Because updates are synchronous, we don't queue them. Instead we force a
141
- // re-render whenever the subscribed state changes by updating an some
142
- // arbitrary useState hook. Then, during render, we call getSnapshot to read
143
- // the current value.
144
- //
145
- // Because we don't actually use the state returned by the useState hook, we
146
- // can save a bit of memory by storing other stuff in that slot.
147
- //
148
- // To implement the early bailout, we need to track some things on a mutable
149
- // object. Usually, we would put that in a useRef hook, but we can stash it in
150
- // our useState hook instead.
151
- //
152
- // To force a re-render, we call forceUpdate({inst}). That works because the
153
- // new object always fails an equality check.
154
-
155
-
156
- var _useState = useState({
157
- inst: {
158
- value: value,
159
- getSnapshot: getSnapshot
160
- }
161
- }),
162
- inst = _useState[0].inst,
163
- forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
164
- // in the layout phase so we can access it during the tearing check that
165
- // happens on subscribe.
166
-
167
-
168
- useLayoutEffect(function () {
169
- inst.value = value;
170
- inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
171
- // commit phase if there was an interleaved mutation. In concurrent mode
172
- // this can happen all the time, but even in synchronous mode, an earlier
173
- // effect may have mutated the store.
174
-
175
- if (checkIfSnapshotChanged(inst)) {
176
- // Force a re-render.
177
- forceUpdate({
178
- inst: inst
179
- });
180
- }
181
- }, [subscribe, value, getSnapshot]);
182
- useEffect(function () {
183
- // Check for changes right before subscribing. Subsequent changes will be
184
- // detected in the subscription handler.
185
- if (checkIfSnapshotChanged(inst)) {
186
- // Force a re-render.
187
- forceUpdate({
188
- inst: inst
189
- });
190
- }
191
-
192
- var handleStoreChange = function () {
193
- // TODO: Because there is no cross-renderer API for batching updates, it's
194
- // up to the consumer of this library to wrap their subscription event
195
- // with unstable_batchedUpdates. Should we try to detect when this isn't
196
- // the case and print a warning in development?
197
- // The store changed. Check if the snapshot changed since the last time we
198
- // read from the store.
199
- if (checkIfSnapshotChanged(inst)) {
200
- // Force a re-render.
201
- forceUpdate({
202
- inst: inst
203
- });
204
- }
205
- }; // Subscribe to the store and return a clean-up function.
206
-
207
-
208
- return subscribe(handleStoreChange);
209
- }, [subscribe]);
210
- useDebugValue(value);
211
- return value;
212
- }
213
-
214
- function checkIfSnapshotChanged(inst) {
215
- var latestGetSnapshot = inst.getSnapshot;
216
- var prevValue = inst.value;
217
-
218
- try {
219
- var nextValue = latestGetSnapshot();
220
- return !objectIs(prevValue, nextValue);
221
- } catch (error) {
222
- return true;
223
- }
224
- }
225
-
226
- var shim = useSyncExternalStore$1;
227
- var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
228
-
229
- exports.useSyncExternalStore = useSyncExternalStore;
230
- if (
231
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
232
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
233
- 'function'
234
- ) {
235
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
236
- }
237
-
68
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
69
+ "function" ===
70
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
71
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
72
+ var React = require("react"),
73
+ objectIs = "function" === typeof Object.is ? Object.is : is,
74
+ useState = React.useState,
75
+ useEffect = React.useEffect,
76
+ useLayoutEffect = React.useLayoutEffect,
77
+ useDebugValue = React.useDebugValue,
78
+ didWarnOld18Alpha = !1,
79
+ didWarnUncachedGetSnapshot = !1;
80
+ exports.useSyncExternalStore =
81
+ void 0 !== React.useSyncExternalStore
82
+ ? React.useSyncExternalStore
83
+ : useSyncExternalStore$1;
84
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
85
+ "function" ===
86
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
87
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
238
88
  })();
239
- }
@@ -8,156 +8,89 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
 
11
- 'use strict';
12
-
13
- if (process.env.NODE_ENV !== "production") {
14
- (function() {
15
- 'use strict';
16
- if (
17
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
18
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
19
- 'function'
20
- ) {
21
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
22
- }
23
- var React = require('react');
24
-
25
- /**
26
- * inlined Object.is polyfill to avoid requiring consumers ship their own
27
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
28
- */
29
- function is(x, y) {
30
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
31
- ;
32
- }
33
-
34
- var objectIs = // $FlowFixMe[method-unbinding]
35
- typeof Object.is === 'function' ? Object.is : is;
36
-
37
- var useSyncExternalStore = React.useSyncExternalStore;
38
-
39
- // for CommonJS interop.
40
-
41
- var useRef = React.useRef,
42
- useEffect = React.useEffect,
43
- useMemo = React.useMemo,
44
- useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
45
-
46
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
47
- // Use this to track the rendered snapshot.
48
- var instRef = useRef(null);
49
- var inst;
50
-
51
- if (instRef.current === null) {
52
- inst = {
53
- hasValue: false,
54
- value: null
55
- };
56
- instRef.current = inst;
57
- } else {
58
- inst = instRef.current;
59
- }
60
-
61
- var _useMemo = useMemo(function () {
62
- // Track the memoized state using closure variables that are local to this
63
- // memoized instance of a getSnapshot function. Intentionally not using a
64
- // useRef hook, because that state would be shared across all concurrent
65
- // copies of the hook/component.
66
- var hasMemo = false;
67
- var memoizedSnapshot;
68
- var memoizedSelection;
69
-
70
- var memoizedSelector = function (nextSnapshot) {
71
- if (!hasMemo) {
72
- // The first time the hook is called, there is no memoized result.
73
- hasMemo = true;
74
- memoizedSnapshot = nextSnapshot;
75
-
76
- var _nextSelection = selector(nextSnapshot);
77
-
78
- if (isEqual !== undefined) {
79
- // Even if the selector has changed, the currently rendered selection
80
- // may be equal to the new selection. We should attempt to reuse the
81
- // current value if possible, to preserve downstream memoizations.
82
- if (inst.hasValue) {
83
- var currentSelection = inst.value;
84
-
85
- if (isEqual(currentSelection, _nextSelection)) {
86
- memoizedSelection = currentSelection;
87
- return currentSelection;
11
+ "use strict";
12
+ "production" !== process.env.NODE_ENV &&
13
+ (function () {
14
+ function is(x, y) {
15
+ return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
16
+ }
17
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
18
+ "function" ===
19
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
20
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
21
+ var React = require("react"),
22
+ objectIs = "function" === typeof Object.is ? Object.is : is,
23
+ useSyncExternalStore = React.useSyncExternalStore,
24
+ useRef = React.useRef,
25
+ useEffect = React.useEffect,
26
+ useMemo = React.useMemo,
27
+ useDebugValue = React.useDebugValue;
28
+ exports.useSyncExternalStoreWithSelector = function (
29
+ subscribe,
30
+ getSnapshot,
31
+ getServerSnapshot,
32
+ selector,
33
+ isEqual
34
+ ) {
35
+ var instRef = useRef(null);
36
+ if (null === instRef.current) {
37
+ var inst = { hasValue: !1, value: null };
38
+ instRef.current = inst;
39
+ } else inst = instRef.current;
40
+ instRef = useMemo(
41
+ function () {
42
+ function memoizedSelector(nextSnapshot) {
43
+ if (!hasMemo) {
44
+ hasMemo = !0;
45
+ memoizedSnapshot = nextSnapshot;
46
+ nextSnapshot = selector(nextSnapshot);
47
+ if (void 0 !== isEqual && inst.hasValue) {
48
+ var currentSelection = inst.value;
49
+ if (isEqual(currentSelection, nextSnapshot))
50
+ return (memoizedSelection = currentSelection);
51
+ }
52
+ return (memoizedSelection = nextSnapshot);
88
53
  }
54
+ currentSelection = memoizedSelection;
55
+ if (objectIs(memoizedSnapshot, nextSnapshot))
56
+ return currentSelection;
57
+ var nextSelection = selector(nextSnapshot);
58
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
59
+ return (memoizedSnapshot = nextSnapshot), currentSelection;
60
+ memoizedSnapshot = nextSnapshot;
61
+ return (memoizedSelection = nextSelection);
89
62
  }
90
- }
91
-
92
- memoizedSelection = _nextSelection;
93
- return _nextSelection;
94
- } // We may be able to reuse the previous invocation's result.
95
-
96
-
97
- // We may be able to reuse the previous invocation's result.
98
- var prevSnapshot = memoizedSnapshot;
99
- var prevSelection = memoizedSelection;
100
-
101
- if (objectIs(prevSnapshot, nextSnapshot)) {
102
- // The snapshot is the same as last time. Reuse the previous selection.
103
- return prevSelection;
104
- } // The snapshot has changed, so we need to compute a new selection.
105
-
106
-
107
- // The snapshot has changed, so we need to compute a new selection.
108
- var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
109
- // has changed. If it hasn't, return the previous selection. That signals
110
- // to React that the selections are conceptually equal, and we can bail
111
- // out of rendering.
112
-
113
- // If a custom isEqual function is provided, use that to check if the data
114
- // has changed. If it hasn't, return the previous selection. That signals
115
- // to React that the selections are conceptually equal, and we can bail
116
- // out of rendering.
117
- if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
118
- return prevSelection;
119
- }
120
-
121
- memoizedSnapshot = nextSnapshot;
122
- memoizedSelection = nextSelection;
123
- return nextSelection;
124
- }; // Assigning this to a constant so that Flow knows it can't change.
125
-
126
-
127
- // Assigning this to a constant so that Flow knows it can't change.
128
- var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
129
-
130
- var getSnapshotWithSelector = function () {
131
- return memoizedSelector(getSnapshot());
132
- };
133
-
134
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
135
- return memoizedSelector(maybeGetServerSnapshot());
63
+ var hasMemo = !1,
64
+ memoizedSnapshot,
65
+ memoizedSelection,
66
+ maybeGetServerSnapshot =
67
+ void 0 === getServerSnapshot ? null : getServerSnapshot;
68
+ return [
69
+ function () {
70
+ return memoizedSelector(getSnapshot());
71
+ },
72
+ null === maybeGetServerSnapshot
73
+ ? void 0
74
+ : function () {
75
+ return memoizedSelector(maybeGetServerSnapshot());
76
+ }
77
+ ];
78
+ },
79
+ [getSnapshot, getServerSnapshot, selector, isEqual]
80
+ );
81
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
82
+ useEffect(
83
+ function () {
84
+ inst.hasValue = !0;
85
+ inst.value = value;
86
+ },
87
+ [value]
88
+ );
89
+ useDebugValue(value);
90
+ return value;
136
91
  };
137
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
138
- }, [getSnapshot, getServerSnapshot, selector, isEqual]),
139
- getSelection = _useMemo[0],
140
- getServerSelection = _useMemo[1];
141
-
142
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
143
- useEffect(function () {
144
- // $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported
145
- inst.hasValue = true; // $FlowFixMe[incompatible-type]
146
-
147
- inst.value = value;
148
- }, [value]);
149
- useDebugValue(value);
150
- return value;
151
- }
152
-
153
- exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
154
- if (
155
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
156
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
157
- 'function'
158
- ) {
159
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
160
- }
161
-
92
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
93
+ "function" ===
94
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
95
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
162
96
  })();
163
- }
@@ -49,7 +49,7 @@ exports.useSyncExternalStoreWithSelector = function (
49
49
  if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
50
50
  var nextSelection = selector(nextSnapshot);
51
51
  if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
52
- return currentSelection;
52
+ return (memoizedSnapshot = nextSnapshot), currentSelection;
53
53
  memoizedSnapshot = nextSnapshot;
54
54
  return (memoizedSelection = nextSelection);
55
55
  }
@@ -8,88 +8,20 @@
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
10
 
11
- 'use strict';
12
-
13
- if (process.env.NODE_ENV !== "production") {
14
- (function() {
15
- 'use strict';
16
- if (
17
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
18
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
19
- 'function'
20
- ) {
21
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
22
- }
23
- var React = require('react');
24
-
25
- var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
26
-
27
- function error(format) {
28
- {
29
- {
30
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
31
- args[_key2 - 1] = arguments[_key2];
32
- }
33
-
34
- printWarning('error', format, args);
35
- }
36
- }
37
- } // eslint-disable-next-line react-internal/no-production-logging
38
-
39
- function printWarning(level, format, args) {
40
- // When changing this logic, you might want to also
41
- // update consoleWithStackDev.www.js as well.
42
- {
43
- var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
44
-
45
- if (ReactSharedInternals.getCurrentStack) {
46
- // We only add the current stack to the console when createTask is not supported.
47
- // Since createTask requires DevTools to be open to work, this means that stacks
48
- // can be lost while DevTools isn't open but we can't detect this.
49
- var stack = ReactSharedInternals.getCurrentStack();
50
-
51
- if (stack !== '') {
52
- format += '%s';
53
- args = args.concat([stack]);
54
- }
55
- }
56
-
57
- if (isErrorLogger) {
58
- // Don't prefix our default logging formatting in ReactFiberErrorLoggger.
59
- // Don't toString the arguments.
60
- args.unshift(format);
61
- } else {
62
- // TODO: Remove this prefix and stop toStringing in the wrapper and
63
- // instead do it at each callsite as needed.
64
- // Careful: RN currently depends on this prefix
65
- // eslint-disable-next-line react-internal/safe-string-coercion
66
- args = args.map(function (item) {
67
- return String(item);
68
- });
69
- args.unshift('Warning: ' + format);
70
- } // We intentionally don't use spread (or .apply) directly because it
71
- // breaks IE9: https://github.com/facebook/react/issues/13610
72
- // eslint-disable-next-line react-internal/no-production-logging
73
-
74
-
75
- Function.prototype.apply.call(console[level], console, args);
76
- }
77
- }
78
-
79
- var useSyncExternalStore = React.useSyncExternalStore;
80
-
81
- {
82
- 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'.");
83
- }
84
-
85
- exports.useSyncExternalStore = useSyncExternalStore;
86
- if (
87
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
88
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
89
- 'function'
90
- ) {
91
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
92
- }
93
-
94
- })();
11
+ "use strict";
12
+ if ("production" !== process.env.NODE_ENV) {
13
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14
+ "function" ===
15
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
16
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
17
+ var useSyncExternalStore$jscomp$inline_1 =
18
+ require("react").useSyncExternalStore;
19
+ console.error(
20
+ "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'."
21
+ );
22
+ exports.useSyncExternalStore = useSyncExternalStore$jscomp$inline_1;
23
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
24
+ "function" ===
25
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
26
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
95
27
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "use-sync-external-store",
3
3
  "description": "Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.",
4
- "version": "1.4.0-rc.0",
4
+ "version": "1.4.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/facebook/react.git",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "license": "MIT",
21
21
  "peerDependencies": {
22
- "react": "19.0.0-rc.0"
22
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "react-17": "npm:react@^17",