@samitouri / QOS-React / commits / d50323eb84

Flatten ReactSharedInternals (#28783)

This is similar to #28771 but for isomorphic. We need a make over for these dispatchers anyway so this is the first step. Also helps flush out some internals usage that will break anyway. It flattens the inner mutable objects onto the ReactSharedInternals.

Sebastian Markbåge committed Apr 8, 2024 at 19:23 UTC d50323eb845c5fde0d720cae888bf35dedd05506
65 files changed +652 -791
packages/react-cache/src/ReactCacheOld.js
+3 -4
@@ -44,12 +44,11 @@ const Pending = 0;
44 const Resolved = 1;
45 const Rejected = 2;
46
47 -const ReactCurrentDispatcher =
48 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
49 - .ReactCurrentDispatcher;
47 +const SharedInternals =
48 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
49
50 function readContext(Context: ReactContext<mixed>) {
52 - const dispatcher = ReactCurrentDispatcher.current;
51 + const dispatcher = SharedInternals.H;
52 if (dispatcher === null) {
53 // This wasn't being minified but we're going to retire this package anyway.
54 // eslint-disable-next-line react-internal/prod-error-codes
packages/react-debug-tools/src/ReactDebugHooks.js
+9 -9
@@ -37,7 +37,7 @@ import {
37 } from 'shared/ReactSymbols';
38 import hasOwnProperty from 'shared/hasOwnProperty';
39
40 -type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;
40 +type CurrentDispatcherRef = typeof ReactSharedInternals;
41
42 // Used to track hooks called during a render
43
@@ -1075,11 +1075,11 @@ export function inspectHooks<Props>(
1075 // DevTools will pass the current renderer's injected dispatcher.
1076 // Other apps might compile debug hooks as part of their app though.
1077 if (currentDispatcher == null) {
1078 - currentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1078 + currentDispatcher = ReactSharedInternals;
1079 }
1080
1081 - const previousDispatcher = currentDispatcher.current;
1082 - currentDispatcher.current = DispatcherProxy;
1081 + const previousDispatcher = currentDispatcher.H;
1082 + currentDispatcher.H = DispatcherProxy;
1083
1084 let readHookLog;
1085 let ancestorStackError;
@@ -1093,7 +1093,7 @@ export function inspectHooks<Props>(
1093 readHookLog = hookLog;
1094 hookLog = [];
1095 // $FlowFixMe[incompatible-use] found when upgrading Flow
1096 - currentDispatcher.current = previousDispatcher;
1096 + currentDispatcher.H = previousDispatcher;
1097 }
1098 const rootStack = ErrorStackParser.parse(ancestorStackError);
1099 return buildTree(rootStack, readHookLog);
@@ -1129,9 +1129,9 @@ function inspectHooksOfForwardRef<Props, Ref>(
1129 ref: Ref,
1130 currentDispatcher: CurrentDispatcherRef,
1131 ): HooksTree {
1132 - const previousDispatcher = currentDispatcher.current;
1132 + const previousDispatcher = currentDispatcher.H;
1133 let readHookLog;
1134 - currentDispatcher.current = DispatcherProxy;
1134 + currentDispatcher.H = DispatcherProxy;
1135 let ancestorStackError;
1136 try {
1137 ancestorStackError = new Error();
@@ -1141,7 +1141,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
1141 } finally {
1142 readHookLog = hookLog;
1143 hookLog = [];
1144 - currentDispatcher.current = previousDispatcher;
1144 + currentDispatcher.H = previousDispatcher;
1145 }
1146 const rootStack = ErrorStackParser.parse(ancestorStackError);
1147 return buildTree(rootStack, readHookLog);
@@ -1169,7 +1169,7 @@ export function inspectHooksOfFiber(
1169 // DevTools will pass the current renderer's injected dispatcher.
1170 // Other apps might compile debug hooks as part of their app though.
1171 if (currentDispatcher == null) {
1172 - currentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1172 + currentDispatcher = ReactSharedInternals;
1173 }
1174
1175 if (
packages/react-debug-tools/src/__tests__/ReactHooksInspection-test.js
-33
@@ -453,39 +453,6 @@ describe('ReactHooksInspection', () => {
453 `);
454 });
455
456 - it('should support an injected dispatcher', () => {
457 - const initial = {
458 - useState() {
459 - throw new Error("Should've been proxied");
460 - },
461 - };
462 - let current = initial;
463 - let getterCalls = 0;
464 - const setterCalls = [];
465 - const FakeDispatcherRef = {
466 - get current() {
467 - getterCalls++;
468 - return current;
469 - },
470 - set current(value) {
471 - setterCalls.push(value);
472 - current = value;
473 - },
474 - };
475 -
476 - function Foo(props) {
477 - const [state] = FakeDispatcherRef.current.useState('hello world');
478 - return <div>{state}</div>;
479 - }
480 -
481 - ReactDebugTools.inspectHooks(Foo, {}, FakeDispatcherRef);
482 -
483 - expect(getterCalls).toBe(2);
484 - expect(setterCalls).toHaveLength(2);
485 - expect(setterCalls[0]).not.toBe(initial);
486 - expect(setterCalls[1]).toBe(initial);
487 - });
488 -
456 it('should inspect use() calls for Promise and Context', async () => {
457 const MyContext = React.createContext('hi');
458 const promise = Promise.resolve('world');
packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js
-55
@@ -2345,61 +2345,6 @@ describe('ReactHooksInspectionIntegration', () => {
2345 `);
2346 });
2347
2348 - it('should support an injected dispatcher', async () => {
2349 - function Foo(props) {
2350 - const [state] = React.useState('hello world');
2351 - return <div>{state}</div>;
2352 - }
2353 -
2354 - const initial = {};
2355 - let current = initial;
2356 - let getterCalls = 0;
2357 - const setterCalls = [];
2358 - const FakeDispatcherRef = {
2359 - get current() {
2360 - getterCalls++;
2361 - return current;
2362 - },
2363 - set current(value) {
2364 - setterCalls.push(value);
2365 - current = value;
2366 - },
2367 - };
2368 -
2369 - let renderer;
2370 - await act(() => {
2371 - renderer = ReactTestRenderer.create(<Foo />, {
2372 - unstable_isConcurrent: true,
2373 - });
2374 - });
2375 - const childFiber = renderer.root._currentFiber();
2376 -
2377 - let didCatch = false;
2378 -
2379 - try {
2380 - ReactDebugTools.inspectHooksOfFiber(childFiber, FakeDispatcherRef);
2381 - } catch (error) {
2382 - expect(error.message).toBe('Error rendering inspected component');
2383 - expect(error.cause).toBeInstanceOf(Error);
2384 - expect(error.cause.message).toBe(
2385 - 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +
2386 - ' one of the following reasons:\n' +
2387 - '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' +
2388 - '2. You might be breaking the Rules of Hooks\n' +
2389 - '3. You might have more than one copy of React in the same app\n' +
2390 - 'See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.',
2391 - );
2392 - didCatch = true;
2393 - }
2394 - // avoid false positive if no error was thrown at all
2395 - expect(didCatch).toBe(true);
2396 -
2397 - expect(getterCalls).toBe(1);
2398 - expect(setterCalls).toHaveLength(2);
2399 - expect(setterCalls[0]).not.toBe(initial);
2400 - expect(setterCalls[1]).toBe(initial);
2401 - });
2402 -
2348 // This test case is based on an open source bug report:
2349 // https://github.com/facebookincubator/redux-react-hook/issues/34#issuecomment-466693787
2350 it('should properly advance the current hook for useContext', async () => {
packages/react-devtools-shared/src/backend/DevToolsComponentStackFrame.js
+3 -3
@@ -86,8 +86,8 @@ export function describeNativeComponentFrame(
86 // Note that unlike the code this was forked from (in ReactComponentStackFrame)
87 // DevTools should override the dispatcher even when DevTools is compiled in production mode,
88 // because the app itself may be in development mode and log errors/warnings.
89 - const previousDispatcher = currentDispatcherRef.current;
90 - currentDispatcherRef.current = null;
89 + const previousDispatcher = currentDispatcherRef.H;
90 + currentDispatcherRef.H = null;
91 disableLogs();
92
93 // NOTE: keep in sync with the implementation in ReactComponentStackFrame
@@ -270,7 +270,7 @@ export function describeNativeComponentFrame(
270
271 Error.prepareStackTrace = previousPrepareStackTrace;
272
273 - currentDispatcherRef.current = previousDispatcher;
273 + currentDispatcherRef.H = previousDispatcher;
274 reenableLogs();
275 }
276 // Fallback to just using the name if we couldn't make it throw.
packages/react-devtools-shared/src/backend/console.js
+7 -9
@@ -9,6 +9,7 @@
9
10 import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
11 import type {
12 + LegacyDispatcherRef,
13 CurrentDispatcherRef,
14 ReactRenderer,
15 WorkTagMap,
@@ -16,7 +17,7 @@ import type {
17 } from './types';
18 import {format, formatWithStyles} from './utils';
19
19 -import {getInternalReactConstants} from './renderer';
20 +import {getInternalReactConstants, getDispatcherRef} from './renderer';
21 import {getStackByFiberInDevAndProd} from './DevToolsFiberComponentStack';
22 import {consoleManagedByDevToolsDuringStrictMode} from 'react-devtools-feature-flags';
23 import {castBool, castBrowserTheme} from '../utils';
@@ -75,7 +76,7 @@ type OnErrorOrWarning = (
76 const injectedRenderers: Map<
77 ReactRenderer,
78 {
78 - currentDispatcherRef: CurrentDispatcherRef,
79 + currentDispatcherRef: LegacyDispatcherRef | CurrentDispatcherRef,
80 getCurrentFiber: () => Fiber | null,
81 onErrorOrWarning: ?OnErrorOrWarning,
82 workTagMap: WorkTagMap,
@@ -215,12 +216,9 @@ export function patch({
216 // Search for the first renderer that has a current Fiber.
217 // We don't handle the edge case of stacks for more than one (e.g. interleaved renderers?)
218 // eslint-disable-next-line no-for-of-loops/no-for-of-loops
218 - for (const {
219 - currentDispatcherRef,
220 - getCurrentFiber,
221 - onErrorOrWarning,
222 - workTagMap,
223 - } of injectedRenderers.values()) {
219 + for (const renderer of injectedRenderers.values()) {
220 + const currentDispatcherRef = getDispatcherRef(renderer);
221 + const {getCurrentFiber, onErrorOrWarning, workTagMap} = renderer;
222 const current: ?Fiber = getCurrentFiber();
223 if (current != null) {
224 try {
@@ -241,7 +239,7 @@ export function patch({
239 const componentStack = getStackByFiberInDevAndProd(
240 workTagMap,
241 current,
244 - currentDispatcherRef,
242 + (currentDispatcherRef: any),
243 );
244 if (componentStack !== '') {
245 if (isStrictModeOverride(args, method)) {
packages/react-devtools-shared/src/backend/renderer.js
+30 -6
@@ -119,6 +119,8 @@ import type {
119 RendererInterface,
120 SerializedElement,
121 WorkTagMap,
122 + CurrentDispatcherRef,
123 + LegacyDispatcherRef,
124 } from './types';
125 import type {
126 ComponentFilter,
@@ -140,6 +142,31 @@ type ReactPriorityLevelsType = {
142 NoPriority: number,
143 };
144
145 +export function getDispatcherRef(renderer: {
146 + +currentDispatcherRef?: LegacyDispatcherRef | CurrentDispatcherRef,
147 + ...
148 +}): void | CurrentDispatcherRef {
149 + if (renderer.currentDispatcherRef === undefined) {
150 + return undefined;
151 + }
152 + const injectedRef = renderer.currentDispatcherRef;
153 + if (
154 + typeof injectedRef.H === 'undefined' &&
155 + typeof injectedRef.current !== 'undefined'
156 + ) {
157 + // We got a legacy dispatcher injected, let's create a wrapper proxy to translate.
158 + return {
159 + get H() {
160 + return (injectedRef: any).current;
161 + },
162 + set H(value) {
163 + (injectedRef: any).current = value;
164 + },
165 + };
166 + }
167 + return (injectedRef: any);
168 +}
169 +
170 function getFiberFlags(fiber: Fiber): number {
171 // The name of this field changed from "effectTag" to "flags"
172 return fiber.flags !== undefined ? fiber.flags : (fiber: any).effectTag;
@@ -694,7 +721,7 @@ export function attach(
721 getDisplayNameForFiber,
722 getIsProfiling: () => isProfiling,
723 getLaneLabelMap,
697 - currentDispatcherRef: renderer.currentDispatcherRef,
724 + currentDispatcherRef: getDispatcherRef(renderer),
725 workTagMap: ReactTypeOfWork,
726 reactVersion: version,
727 });
@@ -3344,10 +3371,7 @@ export function attach(
3371 }
3372
3373 try {
3347 - hooks = inspectHooksOfFiber(
3348 - fiber,
3349 - (renderer.currentDispatcherRef: any),
3350 - );
3374 + hooks = inspectHooksOfFiber(fiber, getDispatcherRef(renderer));
3375 } finally {
3376 // Restore original console functionality.
3377 for (const method in originalConsoleMethods) {
@@ -4571,7 +4595,7 @@ export function attach(
4595 function getComponentStackForFiber(fiber: Fiber): string | null {
4596 let componentStack = fiberToComponentStackMap.get(fiber);
4597 if (componentStack == null) {
4574 - const dispatcherRef = renderer.currentDispatcherRef;
4598 + const dispatcherRef = getDispatcherRef(renderer);
4599 if (dispatcherRef == null) {
4600 return null;
4601 }
packages/react-devtools-shared/src/backend/types.js
+7 -2
@@ -87,7 +87,12 @@ export type NativeType = Object;
87 export type RendererID = number;
88
89 type Dispatcher = any;
90 -export type CurrentDispatcherRef = {current: null | Dispatcher};
90 +export type LegacyDispatcherRef = {current: null | Dispatcher};
91 +type SharedInternalsSubset = {
92 + H: null | Dispatcher,
93 + ...
94 +};
95 +export type CurrentDispatcherRef = SharedInternalsSubset;
96
97 export type GetDisplayNameForFiberID = (
98 id: number,
@@ -155,7 +160,7 @@ export type ReactRenderer = {
160 scheduleUpdate?: ?(fiber: Object) => void,
161 setSuspenseHandler?: ?(shouldSuspend: (fiber: Object) => boolean) => void,
162 // Only injected by React v16.8+ in order to support hooks inspection.
158 - currentDispatcherRef?: CurrentDispatcherRef,
163 + currentDispatcherRef?: LegacyDispatcherRef | CurrentDispatcherRef,
164 // Only injected by React v16.9+ in DEV mode.
165 // Enables DevTools to append owners-only component stack to error messages.
166 getCurrentFiber?: () => Fiber | null,
packages/react-devtools-shared/src/devtools/cache.js
+3 -3
@@ -59,11 +59,11 @@ const Pending = 0;
59 const Resolved = 1;
60 const Rejected = 2;
61
62 -const ReactCurrentDispatcher = (React: any)
63 - .__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;
62 +const ReactSharedInternals = (React: any)
63 + .__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
64
65 function readContext(Context: ReactContext<null>) {
66 - const dispatcher = ReactCurrentDispatcher.current;
66 + const dispatcher = ReactSharedInternals.H;
67 if (dispatcher === null) {
68 throw new Error(
69 'react-cache: read and preload may only be called from within a ' +
packages/react-dom-bindings/src/events/ReactDOMEventListener.js
+6 -8
@@ -56,8 +56,6 @@ import {
56 import ReactSharedInternals from 'shared/ReactSharedInternals';
57 import {isRootDehydrated} from 'react-reconciler/src/ReactFiberShellHydration';
58
59 -const {ReactCurrentBatchConfig} = ReactSharedInternals;
60 -
59 // TODO: can we stop exporting these?
60 let _enabled: boolean = true;
61
@@ -117,15 +115,15 @@ function dispatchDiscreteEvent(
115 container: EventTarget,
116 nativeEvent: AnyNativeEvent,
117 ) {
120 - const prevTransition = ReactCurrentBatchConfig.transition;
121 - ReactCurrentBatchConfig.transition = null;
118 + const prevTransition = ReactSharedInternals.T;
119 + ReactSharedInternals.T = null;
120 const previousPriority = getCurrentUpdatePriority();
121 try {
122 setCurrentUpdatePriority(DiscreteEventPriority);
123 dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
124 } finally {
125 setCurrentUpdatePriority(previousPriority);
128 - ReactCurrentBatchConfig.transition = prevTransition;
126 + ReactSharedInternals.T = prevTransition;
127 }
128 }
129
@@ -135,15 +133,15 @@ function dispatchContinuousEvent(
133 container: EventTarget,
134 nativeEvent: AnyNativeEvent,
135 ) {
138 - const prevTransition = ReactCurrentBatchConfig.transition;
139 - ReactCurrentBatchConfig.transition = null;
136 + const prevTransition = ReactSharedInternals.T;
137 + ReactSharedInternals.T = null;
138 const previousPriority = getCurrentUpdatePriority();
139 try {
140 setCurrentUpdatePriority(ContinuousEventPriority);
141 dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent);
142 } finally {
143 setCurrentUpdatePriority(previousPriority);
146 - ReactCurrentBatchConfig.transition = prevTransition;
144 + ReactSharedInternals.T = prevTransition;
145 }
146 }
147
packages/react-dom-bindings/src/shared/ReactDOMFormActions.js
+1 -3
@@ -13,8 +13,6 @@ import type {Awaited} from 'shared/ReactTypes';
13 import {enableAsyncActions} from 'shared/ReactFeatureFlags';
14 import ReactSharedInternals from 'shared/ReactSharedInternals';
15
16 -const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
17 -
16 type FormStatusNotPending = {|
17 pending: false,
18 data: null,
@@ -47,7 +45,7 @@ export const NotPending: FormStatus = __DEV__
45 function resolveDispatcher() {
46 // Copied from react/src/ReactHooks.js. It's the same thing but in a
47 // different package.
50 - const dispatcher = ReactCurrentDispatcher.current;
48 + const dispatcher = ReactSharedInternals.H;
49 if (__DEV__) {
50 if (dispatcher === null) {
51 console.error(
packages/react-dom/src/__tests__/ReactCompositeComponent-test.js
+9 -6
@@ -14,7 +14,7 @@ let MorphingComponent;
14 let React;
15 let ReactDOM;
16 let ReactDOMClient;
17 -let ReactCurrentOwner;
17 +let ReactSharedInternals;
18 let Scheduler;
19 let assertLog;
20 let act;
@@ -67,9 +67,8 @@ describe('ReactCompositeComponent', () => {
67 React = require('react');
68 ReactDOM = require('react-dom');
69 ReactDOMClient = require('react-dom/client');
70 - ReactCurrentOwner =
71 - require('react').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
72 - .ReactCurrentOwner;
70 + ReactSharedInternals =
71 + require('react').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
72 Scheduler = require('scheduler');
73 assertLog = require('internal-test-utils').assertLog;
74 act = require('internal-test-utils').act;
@@ -545,7 +544,9 @@ describe('ReactCompositeComponent', () => {
544 }
545
546 const instance = <BadComponent />;
548 - expect(ReactCurrentOwner.current).toBe(null);
547 + expect(ReactSharedInternals.owner).toBe(
548 + __DEV__ || !gate(flags => flags.disableStringRefs) ? null : undefined,
549 + );
550
551 const root = ReactDOMClient.createRoot(document.createElement('div'));
552 await expect(async () => {
@@ -554,7 +555,9 @@ describe('ReactCompositeComponent', () => {
555 });
556 }).rejects.toThrow();
557
557 - expect(ReactCurrentOwner.current).toBe(null);
558 + expect(ReactSharedInternals.owner).toBe(
559 + __DEV__ || !gate(flags => flags.disableStringRefs) ? null : undefined,
560 + );
561 });
562
563 it('should call componentWillUnmount before unmounting', async () => {
packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js
+1 -2
@@ -775,8 +775,7 @@ describe('ReactDOMServerHooks', () => {
775 describe('readContext', () => {
776 function readContext(Context) {
777 const dispatcher =
778 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
779 - .ReactCurrentDispatcher.current;
778 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.H;
779 return dispatcher.readContext(Context);
780 }
781
packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js
+1 -2
@@ -161,8 +161,7 @@ describe('ReactDOMServerIntegration', () => {
161 itRenders('readContext() in different components', async render => {
162 function readContext(Ctx) {
163 const dispatcher =
164 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
165 - .ReactCurrentDispatcher.current;
164 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.H;
165 return dispatcher.readContext(Ctx);
166 }
167
packages/react-dom/src/__tests__/ReactServerRendering-test.js
+4 -5
@@ -13,7 +13,7 @@
13 let React;
14 let ReactDOMServer;
15 let PropTypes;
16 -let ReactCurrentDispatcher;
16 +let ReactSharedInternals;
17
18 describe('ReactDOMServer', () => {
19 beforeEach(() => {
@@ -21,9 +21,8 @@ describe('ReactDOMServer', () => {
21 React = require('react');
22 PropTypes = require('prop-types');
23 ReactDOMServer = require('react-dom/server');
24 - ReactCurrentDispatcher =
25 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
26 - .ReactCurrentDispatcher;
24 + ReactSharedInternals =
25 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
26 });
27
28 describe('renderToString', () => {
@@ -420,7 +419,7 @@ describe('ReactDOMServer', () => {
419 const Context = React.createContext(0);
420
421 function readContext(context) {
423 - return ReactCurrentDispatcher.current.readContext(context);
422 + return ReactSharedInternals.H.readContext(context);
423 }
424
425 function Consumer(props) {
packages/react-dom/src/client/ReactDOMRootFB.js
+1 -3
@@ -154,8 +154,6 @@ export function hydrateRoot(
154 );
155 }
156
157 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
158 -
157 let topLevelUpdateWarnings;
158
159 if (__DEV__) {
@@ -344,7 +342,7 @@ export function findDOMNode(
342 componentOrElement: Element | ?React$Component<any, any>,
343 ): null | Element | Text {
344 if (__DEV__) {
347 - const owner = (ReactCurrentOwner.current: any);
345 + const owner = (ReactSharedInternals.owner: any);
346 if (owner !== null && owner.stateNode !== null) {
347 const warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
348 if (!warnedAboutRefsInRender) {
packages/react-dom/src/shared/ReactDOMFlushSync.js
+3 -7
@@ -7,26 +7,22 @@
7 * @flow
8 */
9
10 -import type {BatchConfig} from 'react/src/ReactCurrentBatchConfig';
11 -
10 import {disableLegacyMode} from 'shared/ReactFeatureFlags';
11 import {DiscreteEventPriority} from 'react-reconciler/src/ReactEventPriorities';
12
13 import ReactSharedInternals from 'shared/ReactSharedInternals';
16 -const ReactCurrentBatchConfig: BatchConfig =
17 - ReactSharedInternals.ReactCurrentBatchConfig;
14
15 import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
16
17 declare function flushSyncImpl<R>(fn: () => R): R;
18 declare function flushSyncImpl(void): void;
19 function flushSyncImpl<R>(fn: (() => R) | void): R | void {
24 - const previousTransition = ReactCurrentBatchConfig.transition;
20 + const previousTransition = ReactSharedInternals.T;
21 const previousUpdatePriority =
22 ReactDOMSharedInternals.p; /* ReactDOMCurrentUpdatePriority */
23
24 try {
29 - ReactCurrentBatchConfig.transition = null;
25 + ReactSharedInternals.T = null;
26 ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
27 DiscreteEventPriority;
28 if (fn) {
@@ -35,7 +31,7 @@ function flushSyncImpl<R>(fn: (() => R) | void): R | void {
31 return undefined;
32 }
33 } finally {
38 - ReactCurrentBatchConfig.transition = previousTransition;
34 + ReactSharedInternals.T = previousTransition;
35 ReactDOMSharedInternals.p /* ReactDOMCurrentUpdatePriority */ =
36 previousUpdatePriority;
37 const wasInRender =
packages/react-native-renderer/src/ReactNativePublicCompat.js
+2 -4
@@ -27,13 +27,11 @@ import {doesFiberContain} from 'react-reconciler/src/ReactFiberTreeReflection';
27 import ReactSharedInternals from 'shared/ReactSharedInternals';
28 import getComponentNameFromType from 'shared/getComponentNameFromType';
29
30 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
31 -
30 export function findHostInstance_DEPRECATED<TElementType: ElementType>(
31 componentOrHandle: ?(ElementRef<TElementType> | number),
32 ): ?ElementRef<HostComponent<mixed>> {
33 if (__DEV__) {
36 - const owner = ReactCurrentOwner.current;
34 + const owner = ReactSharedInternals.owner;
35 if (owner !== null && owner.stateNode !== null) {
36 if (!owner.stateNode._warnedAboutRefsInRender) {
37 console.error(
@@ -88,7 +86,7 @@ export function findHostInstance_DEPRECATED<TElementType: ElementType>(
86
87 export function findNodeHandle(componentOrHandle: any): ?number {
88 if (__DEV__) {
91 - const owner = ReactCurrentOwner.current;
89 + const owner = ReactSharedInternals.owner;
90 if (owner !== null && owner.stateNode !== null) {
91 if (!owner.stateNode._warnedAboutRefsInRender) {
92 console.error(
packages/react-noop-renderer/src/createReactNoop.js
+3 -4
@@ -42,7 +42,6 @@ import {
42 } from 'shared/ReactFeatureFlags';
43
44 import ReactSharedInternals from 'shared/ReactSharedInternals';
45 -const ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
45
46 type Container = {
47 rootID: string,
@@ -948,10 +947,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
947 }
948 }
949 if (disableLegacyMode) {
951 - const previousTransition = ReactCurrentBatchConfig.transition;
950 + const previousTransition = ReactSharedInternals.T;
951 const preivousEventPriority = currentEventPriority;
952 try {
954 - ReactCurrentBatchConfig.transition = null;
953 + ReactSharedInternals.T = null;
954 currentEventPriority = DiscreteEventPriority;
955 if (fn) {
956 return fn();
@@ -959,7 +958,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
958 return undefined;
959 }
960 } finally {
962 - ReactCurrentBatchConfig.transition = previousTransition;
961 + ReactSharedInternals.T = previousTransition;
962 currentEventPriority = preivousEventPriority;
963 NoopRenderer.flushSyncWork();
964 }
packages/react-reconciler/src/ReactCurrentFiber.js
+2 -4
@@ -13,8 +13,6 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
13 import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
14 import {getComponentNameFromOwner} from 'react-reconciler/src/getComponentNameFromFiber';
15
16 -const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
17 -
16 export let current: Fiber | null = null;
17 export let isRendering: boolean = false;
18
@@ -45,7 +43,7 @@ function getCurrentFiberStackInDev(): string {
43
44 export function resetCurrentFiber() {
45 if (__DEV__) {
48 - ReactDebugCurrentFrame.getCurrentStack = null;
46 + ReactSharedInternals.getCurrentStack = null;
47 current = null;
48 isRendering = false;
49 }
@@ -53,7 +51,7 @@ export function resetCurrentFiber() {
51
52 export function setCurrentFiber(fiber: Fiber | null) {
53 if (__DEV__) {
56 - ReactDebugCurrentFrame.getCurrentStack =
54 + ReactSharedInternals.getCurrentStack =
55 fiber === null ? null : getCurrentFiberStackInDev;
56 current = fiber;
57 isRendering = false;
packages/react-reconciler/src/ReactFiberAct.js
+4 -3
@@ -13,8 +13,6 @@ import ReactSharedInternals from 'shared/ReactSharedInternals';
13
14 import {warnsIfNotActing} from './ReactFiberConfig';
15
16 -const {ReactCurrentActQueue} = ReactSharedInternals;
17 -
16 export function isLegacyActEnvironment(fiber: Fiber): boolean {
17 if (__DEV__) {
18 // Legacy mode. We preserve the behavior of React 17's act. It assumes an
@@ -47,7 +45,10 @@ export function isConcurrentActEnvironment(): void | boolean {
45 IS_REACT_ACT_ENVIRONMENT
46 : undefined;
47
50 - if (!isReactActEnvironmentGlobal && ReactCurrentActQueue.current !== null) {
48 + if (
49 + !isReactActEnvironmentGlobal &&
50 + ReactSharedInternals.actQueue !== null
51 + ) {
52 // TODO: Include link to relevant documentation page.
53 console.error(
54 'The current testing environment is not configured to support ' +
packages/react-reconciler/src/ReactFiberBeginWork.js
+7 -6
@@ -110,6 +110,7 @@ import {
110 enableRefAsProp,
111 disableLegacyMode,
112 disableDefaultPropsExceptForClasses,
113 + disableStringRefs,
114 } from 'shared/ReactFeatureFlags';
115 import isArray from 'shared/isArray';
116 import shallowEqual from 'shared/shallowEqual';
@@ -297,8 +298,6 @@ import {
298 TransitionTracingMarker,
299 } from './ReactFiberTracingMarkerComponent';
300
300 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
301 -
301 // A special exception that's used to unwind the stack when an update flows
302 // into a dehydrated boundary.
303 export const SelectiveHydrationException: mixed = new Error(
@@ -433,7 +432,7 @@ function updateForwardRef(
432 markComponentRenderStarted(workInProgress);
433 }
434 if (__DEV__) {
436 - ReactCurrentOwner.current = workInProgress;
435 + ReactSharedInternals.owner = workInProgress;
436 setIsRendering(true);
437 nextChildren = renderWithHooks(
438 current,
@@ -1132,7 +1131,7 @@ function updateFunctionComponent(
1131 markComponentRenderStarted(workInProgress);
1132 }
1133 if (__DEV__) {
1135 - ReactCurrentOwner.current = workInProgress;
1134 + ReactSharedInternals.owner = workInProgress;
1135 setIsRendering(true);
1136 nextChildren = renderWithHooks(
1137 current,
@@ -1354,7 +1353,9 @@ function finishClassComponent(
1353 const instance = workInProgress.stateNode;
1354
1355 // Rerender
1357 - ReactCurrentOwner.current = workInProgress;
1356 + if (__DEV__ || !disableStringRefs) {
1357 + ReactSharedInternals.owner = workInProgress;
1358 + }
1359 let nextChildren;
1360 if (
1361 didCaptureError &&
@@ -3399,7 +3400,7 @@ function updateContextConsumer(
3400 }
3401 let newChildren;
3402 if (__DEV__) {
3402 - ReactCurrentOwner.current = workInProgress;
3403 + ReactSharedInternals.owner = workInProgress;
3404 setIsRendering(true);
3405 newChildren = render(newValue);
3406 setIsRendering(false);
packages/react-reconciler/src/ReactFiberErrorLogger.js
+2 -3
@@ -17,7 +17,6 @@ import {ClassComponent} from './ReactWorkTags';
17 import reportGlobalError from 'shared/reportGlobalError';
18
19 import ReactSharedInternals from 'shared/ReactSharedInternals';
20 -const {ReactCurrentActQueue} = ReactSharedInternals;
20
21 // Side-channel since I'm not sure we want to make this part of the public API
22 let componentName: null | string = null;
@@ -111,10 +110,10 @@ export function logUncaughtError(
110 errorBoundaryName = null;
111 }
112 const error = (errorInfo.value: any);
114 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
113 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
114 // For uncaught errors inside act, we track them on the act and then
115 // rethrow them into the test.
117 - ReactCurrentActQueue.thrownErrors.push(error);
116 + ReactSharedInternals.thrownErrors.push(error);
117 return;
118 }
119 const onUncaughtError = root.onUncaughtError;
packages/react-reconciler/src/ReactFiberHooks.js
+89 -104
@@ -157,8 +157,6 @@ import {
157 requestCurrentTransition,
158 } from './ReactFiberTransition';
159
160 -const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;
161 -
160 export type Update<S, A> = {
161 lane: Lane,
162 revertLane: Lane,
@@ -537,19 +535,19 @@ export function renderWithHooks<Props, SecondArg>(
535 // so memoizedState would be null during updates and mounts.
536 if (__DEV__) {
537 if (current !== null && current.memoizedState !== null) {
540 - ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;
538 + ReactSharedInternals.H = HooksDispatcherOnUpdateInDEV;
539 } else if (hookTypesDev !== null) {
540 // This dispatcher handles an edge case where a component is updating,
541 // but no stateful hooks have been used.
542 // We want to match the production code behavior (which will use HooksDispatcherOnMount),
543 // but with the extra DEV validation to ensure hooks ordering hasn't changed.
544 // This dispatcher does that.
547 - ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;
545 + ReactSharedInternals.H = HooksDispatcherOnMountWithHookTypesInDEV;
546 } else {
549 - ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
547 + ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
548 }
549 } else {
552 - ReactCurrentDispatcher.current =
550 + ReactSharedInternals.H =
551 current === null || current.memoizedState === null
552 ? HooksDispatcherOnMount
553 : HooksDispatcherOnUpdate;
@@ -633,7 +631,7 @@ function finishRenderingHooks<Props, SecondArg>(
631
632 // We can assume the previous dispatcher is always this one, since we set it
633 // at the beginning of the render phase and there's no re-entrance.
636 - ReactCurrentDispatcher.current = ContextOnlyDispatcher;
634 + ReactSharedInternals.H = ContextOnlyDispatcher;
635
636 // This check uses currentHook so that it works the same in DEV and prod bundles.
637 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.
@@ -815,7 +813,7 @@ function renderWithHooksAgain<Props, SecondArg>(
813 hookTypesUpdateIndexDev = -1;
814 }
815
818 - ReactCurrentDispatcher.current = __DEV__
816 + ReactSharedInternals.H = __DEV__
817 ? HooksDispatcherOnRerenderInDEV
818 : HooksDispatcherOnRerender;
819
@@ -846,7 +844,7 @@ export function TransitionAwareHostComponent(): TransitionStatus {
844 if (!enableAsyncActions) {
845 throw new Error('Not implemented.');
846 }
849 - const dispatcher = ReactCurrentDispatcher.current;
847 + const dispatcher: any = ReactSharedInternals.H;
848 const [maybeThenable] = dispatcher.useState();
849 if (typeof maybeThenable.then === 'function') {
850 const thenable: Thenable<TransitionStatus> = (maybeThenable: any);
@@ -898,7 +896,7 @@ export function resetHooksAfterThrow(): void {
896
897 // We can assume the previous dispatcher is always this one, since we set it
898 // at the beginning of the render phase and there's no re-entrance.
901 - ReactCurrentDispatcher.current = ContextOnlyDispatcher;
899 + ReactSharedInternals.H = ContextOnlyDispatcher;
900 }
901
902 export function resetHooksOnUnwind(workInProgress: Fiber): void {
@@ -1074,9 +1072,9 @@ function useThenable<T>(thenable: Thenable<T>): T {
1072 // time (perhaps because it threw). Subsequent Hook calls should use the
1073 // mount dispatcher.
1074 if (__DEV__) {
1077 - ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;
1075 + ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
1076 } else {
1079 - ReactCurrentDispatcher.current = HooksDispatcherOnMount;
1077 + ReactSharedInternals.H = HooksDispatcherOnMount;
1078 }
1079 }
1080 return result;
@@ -1977,13 +1975,13 @@ function runActionStateAction<S, P>(
1975 const prevState = actionQueue.state;
1976
1977 // This is a fork of startTransition
1980 - const prevTransition = ReactCurrentBatchConfig.transition;
1978 + const prevTransition = ReactSharedInternals.T;
1979 const currentTransition: BatchConfigTransition = {
1980 _callbacks: new Set<(BatchConfigTransition, mixed) => mixed>(),
1981 };
1984 - ReactCurrentBatchConfig.transition = currentTransition;
1982 + ReactSharedInternals.T = currentTransition;
1983 if (__DEV__) {
1986 - ReactCurrentBatchConfig.transition._updatedFibers = new Set();
1984 + ReactSharedInternals.T._updatedFibers = new Set();
1985 }
1986
1987 // Optimistically update the pending state, similar to useTransition.
@@ -2049,7 +2047,7 @@ function runActionStateAction<S, P>(
2047 (setState: any),
2048 );
2049 } finally {
2052 - ReactCurrentBatchConfig.transition = prevTransition;
2050 + ReactSharedInternals.T = prevTransition;
2051
2052 if (__DEV__) {
2053 if (prevTransition === null && currentTransition._updatedFibers) {
@@ -2795,7 +2793,7 @@ function startTransition<S>(
2793 higherEventPriority(previousPriority, ContinuousEventPriority),
2794 );
2795
2798 - const prevTransition = ReactCurrentBatchConfig.transition;
2796 + const prevTransition = ReactSharedInternals.T;
2797 const currentTransition: BatchConfigTransition = {
2798 _callbacks: new Set<(BatchConfigTransition, mixed) => mixed>(),
2799 };
@@ -2807,23 +2805,23 @@ function startTransition<S>(
2805 // optimistic update anyway to make it less likely the behavior accidentally
2806 // diverges; for example, both an optimistic update and this one should
2807 // share the same lane.
2810 - ReactCurrentBatchConfig.transition = currentTransition;
2808 + ReactSharedInternals.T = currentTransition;
2809 dispatchOptimisticSetState(fiber, false, queue, pendingState);
2810 } else {
2813 - ReactCurrentBatchConfig.transition = null;
2811 + ReactSharedInternals.T = null;
2812 dispatchSetState(fiber, queue, pendingState);
2815 - ReactCurrentBatchConfig.transition = currentTransition;
2813 + ReactSharedInternals.T = currentTransition;
2814 }
2815
2816 if (enableTransitionTracing) {
2817 if (options !== undefined && options.name !== undefined) {
2820 - ReactCurrentBatchConfig.transition.name = options.name;
2821 - ReactCurrentBatchConfig.transition.startTime = now();
2818 + currentTransition.name = options.name;
2819 + currentTransition.startTime = now();
2820 }
2821 }
2822
2823 if (__DEV__) {
2826 - ReactCurrentBatchConfig.transition._updatedFibers = new Set();
2824 + currentTransition._updatedFibers = new Set();
2825 }
2826
2827 try {
@@ -2879,7 +2877,7 @@ function startTransition<S>(
2877 } finally {
2878 setCurrentUpdatePriority(previousPriority);
2879
2882 - ReactCurrentBatchConfig.transition = prevTransition;
2880 + ReactSharedInternals.T = prevTransition;
2881
2882 if (__DEV__) {
2883 if (prevTransition === null && currentTransition._updatedFibers) {
@@ -3216,11 +3214,10 @@ function dispatchSetState<S, A>(
3214 // same as the current state, we may be able to bail out entirely.
3215 const lastRenderedReducer = queue.lastRenderedReducer;
3216 if (lastRenderedReducer !== null) {
3219 - let prevDispatcher;
3217 + let prevDispatcher = null;
3218 if (__DEV__) {
3221 - prevDispatcher = ReactCurrentDispatcher.current;
3222 - ReactCurrentDispatcher.current =
3223 - InvalidNestedHooksDispatcherOnUpdateInDEV;
3219 + prevDispatcher = ReactSharedInternals.H;
3220 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
3221 }
3222 try {
3223 const currentState: S = (queue.lastRenderedState: any);
@@ -3244,7 +3241,7 @@ function dispatchSetState<S, A>(
3241 // Suppress the error. It will throw again in the render phase.
3242 } finally {
3243 if (__DEV__) {
3247 - ReactCurrentDispatcher.current = prevDispatcher;
3244 + ReactSharedInternals.H = prevDispatcher;
3245 }
3246 }
3247 }
@@ -3657,12 +3654,12 @@ if (__DEV__) {
3654 currentHookNameInDev = 'useMemo';
3655 mountHookTypesDev();
3656 checkDepsAreArrayDev(deps);
3660 - const prevDispatcher = ReactCurrentDispatcher.current;
3661 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3657 + const prevDispatcher = ReactSharedInternals.H;
3658 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3659 try {
3660 return mountMemo(create, deps);
3661 } finally {
3665 - ReactCurrentDispatcher.current = prevDispatcher;
3662 + ReactSharedInternals.H = prevDispatcher;
3663 }
3664 },
3665 useReducer<S, I, A>(
@@ -3672,12 +3669,12 @@ if (__DEV__) {
3669 ): [S, Dispatch<A>] {
3670 currentHookNameInDev = 'useReducer';
3671 mountHookTypesDev();
3675 - const prevDispatcher = ReactCurrentDispatcher.current;
3676 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3672 + const prevDispatcher = ReactSharedInternals.H;
3673 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3674 try {
3675 return mountReducer(reducer, initialArg, init);
3676 } finally {
3680 - ReactCurrentDispatcher.current = prevDispatcher;
3677 + ReactSharedInternals.H = prevDispatcher;
3678 }
3679 },
3680 useRef<T>(initialValue: T): {current: T} {
@@ -3690,12 +3687,12 @@ if (__DEV__) {
3687 ): [S, Dispatch<BasicStateAction<S>>] {
3688 currentHookNameInDev = 'useState';
3689 mountHookTypesDev();
3693 - const prevDispatcher = ReactCurrentDispatcher.current;
3694 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3690 + const prevDispatcher = ReactSharedInternals.H;
3691 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3692 try {
3693 return mountState(initialState);
3694 } finally {
3698 - ReactCurrentDispatcher.current = prevDispatcher;
3695 + ReactSharedInternals.H = prevDispatcher;
3696 }
3697 },
3698 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -3836,12 +3833,12 @@ if (__DEV__) {
3833 useMemo<T>(create: () => T, deps: Array<mixed> | void | null): T {
3834 currentHookNameInDev = 'useMemo';
3835 updateHookTypesDev();
3839 - const prevDispatcher = ReactCurrentDispatcher.current;
3840 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3836 + const prevDispatcher = ReactSharedInternals.H;
3837 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3838 try {
3839 return mountMemo(create, deps);
3840 } finally {
3844 - ReactCurrentDispatcher.current = prevDispatcher;
3841 + ReactSharedInternals.H = prevDispatcher;
3842 }
3843 },
3844 useReducer<S, I, A>(
@@ -3851,12 +3848,12 @@ if (__DEV__) {
3848 ): [S, Dispatch<A>] {
3849 currentHookNameInDev = 'useReducer';
3850 updateHookTypesDev();
3854 - const prevDispatcher = ReactCurrentDispatcher.current;
3855 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3851 + const prevDispatcher = ReactSharedInternals.H;
3852 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3853 try {
3854 return mountReducer(reducer, initialArg, init);
3855 } finally {
3859 - ReactCurrentDispatcher.current = prevDispatcher;
3856 + ReactSharedInternals.H = prevDispatcher;
3857 }
3858 },
3859 useRef<T>(initialValue: T): {current: T} {
@@ -3869,12 +3866,12 @@ if (__DEV__) {
3866 ): [S, Dispatch<BasicStateAction<S>>] {
3867 currentHookNameInDev = 'useState';
3868 updateHookTypesDev();
3872 - const prevDispatcher = ReactCurrentDispatcher.current;
3873 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
3869 + const prevDispatcher = ReactSharedInternals.H;
3870 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
3871 try {
3872 return mountState(initialState);
3873 } finally {
3877 - ReactCurrentDispatcher.current = prevDispatcher;
3874 + ReactSharedInternals.H = prevDispatcher;
3875 }
3876 },
3877 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -4017,13 +4014,12 @@ if (__DEV__) {
4014 useMemo<T>(create: () => T, deps: Array<mixed> | void | null): T {
4015 currentHookNameInDev = 'useMemo';
4016 updateHookTypesDev();
4020 - const prevDispatcher = ReactCurrentDispatcher.current;
4021 - ReactCurrentDispatcher.current =
4022 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4017 + const prevDispatcher = ReactSharedInternals.H;
4018 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4019 try {
4020 return updateMemo(create, deps);
4021 } finally {
4026 - ReactCurrentDispatcher.current = prevDispatcher;
4022 + ReactSharedInternals.H = prevDispatcher;
4023 }
4024 },
4025 useReducer<S, I, A>(
@@ -4033,13 +4029,12 @@ if (__DEV__) {
4029 ): [S, Dispatch<A>] {
4030 currentHookNameInDev = 'useReducer';
4031 updateHookTypesDev();
4036 - const prevDispatcher = ReactCurrentDispatcher.current;
4037 - ReactCurrentDispatcher.current =
4038 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4032 + const prevDispatcher = ReactSharedInternals.H;
4033 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4034 try {
4035 return updateReducer(reducer, initialArg, init);
4036 } finally {
4042 - ReactCurrentDispatcher.current = prevDispatcher;
4037 + ReactSharedInternals.H = prevDispatcher;
4038 }
4039 },
4040 useRef<T>(initialValue: T): {current: T} {
@@ -4052,13 +4047,12 @@ if (__DEV__) {
4047 ): [S, Dispatch<BasicStateAction<S>>] {
4048 currentHookNameInDev = 'useState';
4049 updateHookTypesDev();
4055 - const prevDispatcher = ReactCurrentDispatcher.current;
4056 - ReactCurrentDispatcher.current =
4057 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4050 + const prevDispatcher = ReactSharedInternals.H;
4051 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4052 try {
4053 return updateState(initialState);
4054 } finally {
4061 - ReactCurrentDispatcher.current = prevDispatcher;
4055 + ReactSharedInternals.H = prevDispatcher;
4056 }
4057 },
4058 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -4200,13 +4194,12 @@ if (__DEV__) {
4194 useMemo<T>(create: () => T, deps: Array<mixed> | void | null): T {
4195 currentHookNameInDev = 'useMemo';
4196 updateHookTypesDev();
4203 - const prevDispatcher = ReactCurrentDispatcher.current;
4204 - ReactCurrentDispatcher.current =
4205 - InvalidNestedHooksDispatcherOnRerenderInDEV;
4197 + const prevDispatcher = ReactSharedInternals.H;
4198 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnRerenderInDEV;
4199 try {
4200 return updateMemo(create, deps);
4201 } finally {
4209 - ReactCurrentDispatcher.current = prevDispatcher;
4202 + ReactSharedInternals.H = prevDispatcher;
4203 }
4204 },
4205 useReducer<S, I, A>(
@@ -4216,13 +4209,12 @@ if (__DEV__) {
4209 ): [S, Dispatch<A>] {
4210 currentHookNameInDev = 'useReducer';
4211 updateHookTypesDev();
4219 - const prevDispatcher = ReactCurrentDispatcher.current;
4220 - ReactCurrentDispatcher.current =
4221 - InvalidNestedHooksDispatcherOnRerenderInDEV;
4212 + const prevDispatcher = ReactSharedInternals.H;
4213 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnRerenderInDEV;
4214 try {
4215 return rerenderReducer(reducer, initialArg, init);
4216 } finally {
4225 - ReactCurrentDispatcher.current = prevDispatcher;
4217 + ReactSharedInternals.H = prevDispatcher;
4218 }
4219 },
4220 useRef<T>(initialValue: T): {current: T} {
@@ -4235,13 +4227,12 @@ if (__DEV__) {
4227 ): [S, Dispatch<BasicStateAction<S>>] {
4228 currentHookNameInDev = 'useState';
4229 updateHookTypesDev();
4238 - const prevDispatcher = ReactCurrentDispatcher.current;
4239 - ReactCurrentDispatcher.current =
4240 - InvalidNestedHooksDispatcherOnRerenderInDEV;
4230 + const prevDispatcher = ReactSharedInternals.H;
4231 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnRerenderInDEV;
4232 try {
4233 return rerenderState(initialState);
4234 } finally {
4244 - ReactCurrentDispatcher.current = prevDispatcher;
4235 + ReactSharedInternals.H = prevDispatcher;
4236 }
4237 },
4238 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -4394,12 +4385,12 @@ if (__DEV__) {
4385 currentHookNameInDev = 'useMemo';
4386 warnInvalidHookAccess();
4387 mountHookTypesDev();
4397 - const prevDispatcher = ReactCurrentDispatcher.current;
4398 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
4388 + const prevDispatcher = ReactSharedInternals.H;
4389 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
4390 try {
4391 return mountMemo(create, deps);
4392 } finally {
4402 - ReactCurrentDispatcher.current = prevDispatcher;
4393 + ReactSharedInternals.H = prevDispatcher;
4394 }
4395 },
4396 useReducer<S, I, A>(
@@ -4410,12 +4401,12 @@ if (__DEV__) {
4401 currentHookNameInDev = 'useReducer';
4402 warnInvalidHookAccess();
4403 mountHookTypesDev();
4413 - const prevDispatcher = ReactCurrentDispatcher.current;
4414 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
4404 + const prevDispatcher = ReactSharedInternals.H;
4405 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
4406 try {
4407 return mountReducer(reducer, initialArg, init);
4408 } finally {
4418 - ReactCurrentDispatcher.current = prevDispatcher;
4409 + ReactSharedInternals.H = prevDispatcher;
4410 }
4411 },
4412 useRef<T>(initialValue: T): {current: T} {
@@ -4430,12 +4421,12 @@ if (__DEV__) {
4421 currentHookNameInDev = 'useState';
4422 warnInvalidHookAccess();
4423 mountHookTypesDev();
4433 - const prevDispatcher = ReactCurrentDispatcher.current;
4434 - ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;
4424 + const prevDispatcher = ReactSharedInternals.H;
4425 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnMountInDEV;
4426 try {
4427 return mountState(initialState);
4428 } finally {
4438 - ReactCurrentDispatcher.current = prevDispatcher;
4429 + ReactSharedInternals.H = prevDispatcher;
4430 }
4431 },
4432 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -4600,13 +4591,12 @@ if (__DEV__) {
4591 currentHookNameInDev = 'useMemo';
4592 warnInvalidHookAccess();
4593 updateHookTypesDev();
4603 - const prevDispatcher = ReactCurrentDispatcher.current;
4604 - ReactCurrentDispatcher.current =
4605 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4594 + const prevDispatcher = ReactSharedInternals.H;
4595 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4596 try {
4597 return updateMemo(create, deps);
4598 } finally {
4609 - ReactCurrentDispatcher.current = prevDispatcher;
4599 + ReactSharedInternals.H = prevDispatcher;
4600 }
4601 },
4602 useReducer<S, I, A>(
@@ -4617,13 +4607,12 @@ if (__DEV__) {
4607 currentHookNameInDev = 'useReducer';
4608 warnInvalidHookAccess();
4609 updateHookTypesDev();
4620 - const prevDispatcher = ReactCurrentDispatcher.current;
4621 - ReactCurrentDispatcher.current =
4622 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4610 + const prevDispatcher = ReactSharedInternals.H;
4611 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4612 try {
4613 return updateReducer(reducer, initialArg, init);
4614 } finally {
4626 - ReactCurrentDispatcher.current = prevDispatcher;
4615 + ReactSharedInternals.H = prevDispatcher;
4616 }
4617 },
4618 useRef<T>(initialValue: T): {current: T} {
@@ -4638,13 +4627,12 @@ if (__DEV__) {
4627 currentHookNameInDev = 'useState';
4628 warnInvalidHookAccess();
4629 updateHookTypesDev();
4641 - const prevDispatcher = ReactCurrentDispatcher.current;
4642 - ReactCurrentDispatcher.current =
4643 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4630 + const prevDispatcher = ReactSharedInternals.H;
4631 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4632 try {
4633 return updateState(initialState);
4634 } finally {
4647 - ReactCurrentDispatcher.current = prevDispatcher;
4635 + ReactSharedInternals.H = prevDispatcher;
4636 }
4637 },
4638 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
@@ -4809,13 +4797,12 @@ if (__DEV__) {
4797 currentHookNameInDev = 'useMemo';
4798 warnInvalidHookAccess();
4799 updateHookTypesDev();
4812 - const prevDispatcher = ReactCurrentDispatcher.current;
4813 - ReactCurrentDispatcher.current =
4814 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4800 + const prevDispatcher = ReactSharedInternals.H;
4801 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4802 try {
4803 return updateMemo(create, deps);
4804 } finally {
4818 - ReactCurrentDispatcher.current = prevDispatcher;
4805 + ReactSharedInternals.H = prevDispatcher;
4806 }
4807 },
4808 useReducer<S, I, A>(
@@ -4826,13 +4813,12 @@ if (__DEV__) {
4813 currentHookNameInDev = 'useReducer';
4814 warnInvalidHookAccess();
4815 updateHookTypesDev();
4829 - const prevDispatcher = ReactCurrentDispatcher.current;
4830 - ReactCurrentDispatcher.current =
4831 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4816 + const prevDispatcher = ReactSharedInternals.H;
4817 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4818 try {
4819 return rerenderReducer(reducer, initialArg, init);
4820 } finally {
4835 - ReactCurrentDispatcher.current = prevDispatcher;
4821 + ReactSharedInternals.H = prevDispatcher;
4822 }
4823 },
4824 useRef<T>(initialValue: T): {current: T} {
@@ -4847,13 +4833,12 @@ if (__DEV__) {
4833 currentHookNameInDev = 'useState';
4834 warnInvalidHookAccess();
4835 updateHookTypesDev();
4850 - const prevDispatcher = ReactCurrentDispatcher.current;
4851 - ReactCurrentDispatcher.current =
4852 - InvalidNestedHooksDispatcherOnUpdateInDEV;
4836 + const prevDispatcher = ReactSharedInternals.H;
4837 + ReactSharedInternals.H = InvalidNestedHooksDispatcherOnUpdateInDEV;
4838 try {
4839 return rerenderState(initialState);
4840 } finally {
4856 - ReactCurrentDispatcher.current = prevDispatcher;
4841 + ReactSharedInternals.H = prevDispatcher;
4842 }
4843 },
4844 useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {
packages/react-reconciler/src/ReactFiberReconciler.js
+1 -2
@@ -859,7 +859,6 @@ function getCurrentFiberForDevTools() {
859
860 export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {
861 const {findFiberByHostInstance} = devToolsConfig;
862 - const {ReactCurrentDispatcher} = ReactSharedInternals;
862
863 return injectInternals({
864 bundleType: devToolsConfig.bundleType,
@@ -875,7 +874,7 @@ export function injectIntoDevTools(devToolsConfig: DevToolsConfig): boolean {
874 setErrorHandler,
875 setSuspenseHandler,
876 scheduleUpdate,
878 - currentDispatcherRef: ReactCurrentDispatcher,
877 + currentDispatcherRef: ReactSharedInternals,
878 findHostInstanceByFiber,
879 findFiberByHostInstance:
880 findFiberByHostInstance || emptyFindFiberByHostInstance,
packages/react-reconciler/src/ReactFiberRootScheduler.js
+8 -9
@@ -62,7 +62,6 @@ import {
62 } from './ReactFiberConfig';
63
64 import ReactSharedInternals from 'shared/ReactSharedInternals';
65 -const {ReactCurrentActQueue} = ReactSharedInternals;
65
66 // A linked list of all the roots with pending work. In an idiomatic app,
67 // there's only a single root, but we do support multi root apps, hence this
@@ -111,7 +110,7 @@ export function ensureRootIsScheduled(root: FiberRoot): void {
110
111 // At the end of the current event, go through each of the roots and ensure
112 // there's a task scheduled for each one at the correct priority.
114 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
113 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
114 // We're inside an `act` scope.
115 if (!didScheduleMicrotask_act) {
116 didScheduleMicrotask_act = true;
@@ -135,11 +134,11 @@ export function ensureRootIsScheduled(root: FiberRoot): void {
134 if (
135 __DEV__ &&
136 !disableLegacyMode &&
138 - ReactCurrentActQueue.isBatchingLegacy &&
137 + ReactSharedInternals.isBatchingLegacy &&
138 root.tag === LegacyRoot
139 ) {
140 // Special `act` case: Record whenever a legacy update is scheduled.
142 - ReactCurrentActQueue.didScheduleLegacyUpdate = true;
141 + ReactSharedInternals.didScheduleLegacyUpdate = true;
142 }
143 }
144
@@ -333,7 +332,7 @@ function scheduleTaskForRootDuringMicrotask(
332 // on the `act` queue.
333 !(
334 __DEV__ &&
336 - ReactCurrentActQueue.current !== null &&
335 + ReactSharedInternals.actQueue !== null &&
336 existingCallbackNode !== fakeActCallbackNode
337 )
338 ) {
@@ -403,11 +402,11 @@ function scheduleCallback(
402 priorityLevel: PriorityLevel,
403 callback: RenderTaskFn,
404 ) {
406 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
405 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
406 // Special case: We're inside an `act` scope (a testing utility).
407 // Instead of scheduling work in the host environment, add it to a
408 // fake internal queue that's managed by the `act` implementation.
410 - ReactCurrentActQueue.current.push(callback);
409 + ReactSharedInternals.actQueue.push(callback);
410 return fakeActCallbackNode;
411 } else {
412 return Scheduler_scheduleCallback(priorityLevel, callback);
@@ -424,13 +423,13 @@ function cancelCallback(callbackNode: mixed) {
423 }
424
425 function scheduleImmediateTask(cb: () => mixed) {
427 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
426 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
427 // Special case: Inside an `act` scope, we push microtasks to the fake `act`
428 // callback queue. This is because we currently support calling `act`
429 // without awaiting the result. The plan is to deprecate that, and require
430 // that you always await the result so that the microtasks have a chance to
431 // run. But it hasn't happened yet.
433 - ReactCurrentActQueue.current.push(() => {
432 + ReactSharedInternals.actQueue.push(() => {
433 cb();
434 return null;
435 });
packages/react-reconciler/src/ReactFiberThenable.js
+2 -3
@@ -17,7 +17,6 @@ import type {
17 import {getWorkInProgressRoot} from './ReactFiberWorkLoop';
18
19 import ReactSharedInternals from 'shared/ReactSharedInternals';
20 -const {ReactCurrentActQueue} = ReactSharedInternals;
20
21 opaque type ThenableStateDev = {
22 didWarnAboutUncachedPromise: boolean,
@@ -95,8 +94,8 @@ export function trackUsedThenable<T>(
94 thenable: Thenable<T>,
95 index: number,
96 ): T {
98 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
99 - ReactCurrentActQueue.didUsePromise = true;
97 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
98 + ReactSharedInternals.didUsePromise = true;
99 }
100 const trackedThenables = getThenablesFromState(thenableState);
101 const previous = trackedThenables[index];
packages/react-reconciler/src/ReactFiberTracingMarkerComponent.js
+1
@@ -40,6 +40,7 @@ export type PendingTransitionCallbacks = {
40 export type Transition = {
41 name: string,
42 startTime: number,
43 + ...
44 };
45
46 export type BatchConfigTransition = {
packages/react-reconciler/src/ReactFiberTransition.js
+2 -4
@@ -36,16 +36,14 @@ import {
36 import ReactSharedInternals from 'shared/ReactSharedInternals';
37 import {entangleAsyncAction} from './ReactFiberAsyncAction';
38
39 -const {ReactCurrentBatchConfig} = ReactSharedInternals;
40 -
39 export const NoTransition = null;
40
41 export function requestCurrentTransition(): BatchConfigTransition | null {
44 - const transition = ReactCurrentBatchConfig.transition;
42 + const transition = ReactSharedInternals.T;
43 if (transition !== null) {
44 // Whenever a transition update is scheduled, register a callback on the
45 // transition object so we can get the return value of the scope function.
48 - transition._callbacks.add(handleAsyncAction);
46 + transition._callbacks.add((handleAsyncAction: any));
47 }
48 return transition;
49 }
packages/react-reconciler/src/ReactFiberTreeReflection.js
+1 -3
@@ -26,8 +26,6 @@ import {
26 } from './ReactWorkTags';
27 import {NoFlags, Placement, Hydrating} from './ReactFiberFlags';
28
29 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
30 -
29 export function getNearestMountedFiber(fiber: Fiber): null | Fiber {
30 let node = fiber;
31 let nearestMounted: null | Fiber = fiber;
@@ -91,7 +89,7 @@ export function isFiberMounted(fiber: Fiber): boolean {
89
90 export function isMounted(component: React$Component<any, any>): boolean {
91 if (__DEV__) {
94 - const owner = (ReactCurrentOwner.current: any);
92 + const owner = (ReactSharedInternals.owner: any);
93 if (owner !== null && owner.tag === ClassComponent) {
94 const ownerFiber: Fiber = owner;
95 const instance = ownerFiber.stateNode;
packages/react-reconciler/src/ReactFiberWorkLoop.js
+45 -47
@@ -9,7 +9,6 @@
9
10 import {REACT_STRICT_MODE_TYPE} from 'shared/ReactSymbols';
11
12 -import type {BatchConfig} from 'react/src/ReactCurrentBatchConfig';
12 import type {Wakeable, Thenable} from 'shared/ReactTypes';
13 import type {Fiber, FiberRoot} from './ReactInternalTypes';
14 import type {Lanes, Lane} from './ReactFiberLane';
@@ -42,6 +41,7 @@ import {
41 enableInfiniteRenderLoopDetection,
42 disableLegacyMode,
43 disableDefaultPropsExceptForClasses,
44 + disableStringRefs,
45 } from 'shared/ReactFeatureFlags';
46 import ReactSharedInternals from 'shared/ReactSharedInternals';
47 import is from 'shared/objectIs';
@@ -282,13 +282,6 @@ import {logUncaughtError} from './ReactFiberErrorLogger';
282
283 const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
284
285 -const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
286 -const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
287 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
288 -const ReactCurrentBatchConfig: BatchConfig =
289 - ReactSharedInternals.ReactCurrentBatchConfig;
290 -const ReactCurrentActQueue = ReactSharedInternals.ReactCurrentActQueue;
291 -
285 type ExecutionContext = number;
286
287 export const NoContext = /* */ 0b000;
@@ -628,7 +621,6 @@ export function requestUpdateLane(fiber: Fiber): Lane {
621 if (!transition._updatedFibers) {
622 transition._updatedFibers = new Set();
623 }
631 -
624 transition._updatedFibers.add(fiber);
625 }
626
@@ -769,7 +761,7 @@ export function scheduleUpdateOnFiber(
761 warnIfUpdatesNotWrappedWithActDEV(fiber);
762
763 if (enableTransitionTracing) {
772 - const transition = ReactCurrentBatchConfig.transition;
764 + const transition = ReactSharedInternals.T;
765 if (transition !== null && transition.name != null) {
766 if (transition.startTime === -1) {
767 transition.startTime = now();
@@ -812,7 +804,7 @@ export function scheduleUpdateOnFiber(
804 !disableLegacyMode &&
805 (fiber.mode & ConcurrentMode) === NoMode
806 ) {
815 - if (__DEV__ && ReactCurrentActQueue.isBatchingLegacy) {
807 + if (__DEV__ && ReactSharedInternals.isBatchingLegacy) {
808 // Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
809 } else {
810 // Flush the synchronous work now, unless we're already working or inside
@@ -1431,16 +1423,15 @@ export function getExecutionContext(): ExecutionContext {
1423 }
1424
1425 export function deferredUpdates<A>(fn: () => A): A {
1434 - const prevTransition = ReactCurrentBatchConfig.transition;
1435 -
1426 + const prevTransition = ReactSharedInternals.T;
1427 const previousPriority = getCurrentUpdatePriority();
1428 try {
1429 setCurrentUpdatePriority(DefaultEventPriority);
1439 - ReactCurrentBatchConfig.transition = null;
1430 + ReactSharedInternals.T = null;
1431 return fn();
1432 } finally {
1433 setCurrentUpdatePriority(previousPriority);
1443 - ReactCurrentBatchConfig.transition = prevTransition;
1434 + ReactSharedInternals.T = prevTransition;
1435 }
1436 }
1437
@@ -1461,7 +1452,7 @@ export function batchedUpdates<A, R>(fn: A => R, a: A): R {
1452 if (
1453 executionContext === NoContext &&
1454 // Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
1464 - !(__DEV__ && ReactCurrentActQueue.isBatchingLegacy)
1455 + !(__DEV__ && ReactSharedInternals.isBatchingLegacy)
1456 ) {
1457 resetRenderTimer();
1458 flushSyncWorkOnLegacyRootsOnly();
@@ -1477,15 +1468,15 @@ export function discreteUpdates<A, B, C, D, R>(
1468 c: C,
1469 d: D,
1470 ): R {
1480 - const prevTransition = ReactCurrentBatchConfig.transition;
1471 + const prevTransition = ReactSharedInternals.T;
1472 const previousPriority = getCurrentUpdatePriority();
1473 try {
1474 setCurrentUpdatePriority(DiscreteEventPriority);
1484 - ReactCurrentBatchConfig.transition = null;
1475 + ReactSharedInternals.T = null;
1476 return fn(a, b, c, d);
1477 } finally {
1478 setCurrentUpdatePriority(previousPriority);
1488 - ReactCurrentBatchConfig.transition = prevTransition;
1479 + ReactSharedInternals.T = prevTransition;
1480 if (executionContext === NoContext) {
1481 resetRenderTimer();
1482 }
@@ -1514,12 +1505,12 @@ export function flushSyncFromReconciler<R>(fn: (() => R) | void): R | void {
1505 const prevExecutionContext = executionContext;
1506 executionContext |= BatchedContext;
1507
1517 - const prevTransition = ReactCurrentBatchConfig.transition;
1508 + const prevTransition = ReactSharedInternals.T;
1509 const previousPriority = getCurrentUpdatePriority();
1510
1511 try {
1512 setCurrentUpdatePriority(DiscreteEventPriority);
1522 - ReactCurrentBatchConfig.transition = null;
1513 + ReactSharedInternals.T = null;
1514 if (fn) {
1515 return fn();
1516 } else {
@@ -1527,7 +1518,7 @@ export function flushSyncFromReconciler<R>(fn: (() => R) | void): R | void {
1518 }
1519 } finally {
1520 setCurrentUpdatePriority(previousPriority);
1530 - ReactCurrentBatchConfig.transition = prevTransition;
1521 + ReactSharedInternals.T = prevTransition;
1522
1523 executionContext = prevExecutionContext;
1524 // Flush the immediate callbacks that were scheduled during this batch.
@@ -1679,7 +1670,9 @@ function handleThrow(root: FiberRoot, thrownValue: any): void {
1670 // when React is executing user code.
1671 resetHooksAfterThrow();
1672 resetCurrentDebugFiberInDEV();
1682 - ReactCurrentOwner.current = null;
1673 + if (__DEV__ || !disableStringRefs) {
1674 + ReactSharedInternals.owner = null;
1675 + }
1676
1677 if (thrownValue === SuspenseException) {
1678 // This is a special type of exception used for Suspense. For historical
@@ -1852,8 +1845,8 @@ export function shouldRemainOnPreviousScreen(): boolean {
1845 }
1846
1847 function pushDispatcher(container: any) {
1855 - const prevDispatcher = ReactCurrentDispatcher.current;
1856 - ReactCurrentDispatcher.current = ContextOnlyDispatcher;
1848 + const prevDispatcher = ReactSharedInternals.H;
1849 + ReactSharedInternals.H = ContextOnlyDispatcher;
1850 if (prevDispatcher === null) {
1851 // The React isomorphic package does not include a default dispatcher.
1852 // Instead the first renderer will lazily attach one, in order to give
@@ -1865,13 +1858,13 @@ function pushDispatcher(container: any) {
1858 }
1859
1860 function popDispatcher(prevDispatcher: any) {
1868 - ReactCurrentDispatcher.current = prevDispatcher;
1861 + ReactSharedInternals.H = prevDispatcher;
1862 }
1863
1864 function pushCacheDispatcher() {
1865 if (enableCache) {
1873 - const prevCacheDispatcher = ReactCurrentCache.current;
1874 - ReactCurrentCache.current = DefaultCacheDispatcher;
1866 + const prevCacheDispatcher = ReactSharedInternals.C;
1867 + ReactSharedInternals.C = DefaultCacheDispatcher;
1868 return prevCacheDispatcher;
1869 } else {
1870 return null;
@@ -1880,7 +1873,7 @@ function pushCacheDispatcher() {
1873
1874 function popCacheDispatcher(prevCacheDispatcher: any) {
1875 if (enableCache) {
1883 - ReactCurrentCache.current = prevCacheDispatcher;
1876 + ReactSharedInternals.C = prevCacheDispatcher;
1877 }
1878 }
1879
@@ -2293,7 +2286,7 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
2286 }
2287 }
2288
2296 - if (__DEV__ && ReactCurrentActQueue.current !== null) {
2289 + if (__DEV__ && ReactSharedInternals.actQueue !== null) {
2290 // `act` special case: If we're inside an `act` scope, don't consult
2291 // `shouldYield`. Always keep working until the render is complete.
2292 // This is not just an optimization: in a unit test environment, we
@@ -2379,7 +2372,9 @@ function performUnitOfWork(unitOfWork: Fiber): void {
2372 workInProgress = next;
2373 }
2374
2382 - ReactCurrentOwner.current = null;
2375 + if (__DEV__ || !disableStringRefs) {
2376 + ReactSharedInternals.owner = null;
2377 + }
2378 }
2379
2380 function replaySuspendedUnitOfWork(unitOfWork: Fiber): void {
@@ -2492,7 +2487,9 @@ function replaySuspendedUnitOfWork(unitOfWork: Fiber): void {
2487 workInProgress = next;
2488 }
2489
2495 - ReactCurrentOwner.current = null;
2490 + if (__DEV__ || !disableStringRefs) {
2491 + ReactSharedInternals.owner = null;
2492 + }
2493 }
2494
2495 function throwAndUnwindWorkLoop(
@@ -2710,12 +2707,11 @@ function commitRoot(
2707 ) {
2708 // TODO: This no longer makes any sense. We already wrap the mutation and
2709 // layout phases. Should be able to remove.
2713 - const prevTransition = ReactCurrentBatchConfig.transition;
2714 -
2710 + const prevTransition = ReactSharedInternals.T;
2711 const previousUpdateLanePriority = getCurrentUpdatePriority();
2712 try {
2713 setCurrentUpdatePriority(DiscreteEventPriority);
2718 - ReactCurrentBatchConfig.transition = null;
2714 + ReactSharedInternals.T = null;
2715 commitRootImpl(
2716 root,
2717 recoverableErrors,
@@ -2725,7 +2721,7 @@ function commitRoot(
2721 spawnedLane,
2722 );
2723 } finally {
2728 - ReactCurrentBatchConfig.transition = prevTransition;
2724 + ReactSharedInternals.T = prevTransition;
2725 setCurrentUpdatePriority(previousUpdateLanePriority);
2726 }
2727
@@ -2875,8 +2871,8 @@ function commitRootImpl(
2871 NoFlags;
2872
2873 if (subtreeHasEffects || rootHasEffect) {
2878 - const prevTransition = ReactCurrentBatchConfig.transition;
2879 - ReactCurrentBatchConfig.transition = null;
2874 + const prevTransition = ReactSharedInternals.T;
2875 + ReactSharedInternals.T = null;
2876 const previousPriority = getCurrentUpdatePriority();
2877 setCurrentUpdatePriority(DiscreteEventPriority);
2878
@@ -2884,7 +2880,9 @@ function commitRootImpl(
2880 executionContext |= CommitContext;
2881
2882 // Reset this to null before calling lifecycles
2887 - ReactCurrentOwner.current = null;
2883 + if (__DEV__ || !disableStringRefs) {
2884 + ReactSharedInternals.owner = null;
2885 + }
2886
2887 // The commit phase is broken into several sub-phases. We do a separate pass
2888 // of the effect list for each phase: all mutation effects come before all
@@ -2950,7 +2948,7 @@ function commitRootImpl(
2948
2949 // Reset the priority to the previous non-sync value.
2950 setCurrentUpdatePriority(previousPriority);
2953 - ReactCurrentBatchConfig.transition = prevTransition;
2951 + ReactSharedInternals.T = prevTransition;
2952 } else {
2953 // No effects.
2954 root.current = finishedWork;
@@ -3180,16 +3178,16 @@ export function flushPassiveEffects(): boolean {
3178
3179 const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes);
3180 const priority = lowerEventPriority(DefaultEventPriority, renderPriority);
3183 - const prevTransition = ReactCurrentBatchConfig.transition;
3181 + const prevTransition = ReactSharedInternals.T;
3182 const previousPriority = getCurrentUpdatePriority();
3183
3184 try {
3185 setCurrentUpdatePriority(priority);
3188 - ReactCurrentBatchConfig.transition = null;
3186 + ReactSharedInternals.T = null;
3187 return flushPassiveEffectsImpl();
3188 } finally {
3189 setCurrentUpdatePriority(previousPriority);
3192 - ReactCurrentBatchConfig.transition = prevTransition;
3190 + ReactSharedInternals.T = prevTransition;
3191
3192 // Once passive effects have run for the tree - giving components a
3193 // chance to retain cache instances they use - release the pooled
@@ -3921,7 +3919,7 @@ function scheduleCallback(priorityLevel: any, callback) {
3919 if (__DEV__) {
3920 // If we're currently inside an `act` scope, bypass Scheduler and push to
3921 // the `act` queue instead.
3924 - const actQueue = ReactCurrentActQueue.current;
3922 + const actQueue = ReactSharedInternals.actQueue;
3923 if (actQueue !== null) {
3924 actQueue.push(callback);
3925 return fakeActCallbackNode;
@@ -3936,7 +3934,7 @@ function scheduleCallback(priorityLevel: any, callback) {
3934
3935 function shouldForceFlushFallbacksInDEV() {
3936 // Never force flush in production. This function should get stripped out.
3939 - return __DEV__ && ReactCurrentActQueue.current !== null;
3937 + return __DEV__ && ReactSharedInternals.actQueue !== null;
3938 }
3939
3940 function warnIfUpdatesNotWrappedWithActDEV(fiber: Fiber): void {
@@ -3968,7 +3966,7 @@ function warnIfUpdatesNotWrappedWithActDEV(fiber: Fiber): void {
3966 }
3967 }
3968
3971 - if (ReactCurrentActQueue.current === null) {
3969 + if (ReactSharedInternals.actQueue === null) {
3970 const previousFiber = ReactCurrentFiberCurrent;
3971 try {
3972 setCurrentDebugFiberInDEV(fiber);
@@ -4001,7 +3999,7 @@ function warnIfSuspenseResolutionNotWrappedWithActDEV(root: FiberRoot): void {
3999 if (
4000 (disableLegacyMode || root.tag !== LegacyRoot) &&
4001 isConcurrentActEnvironment() &&
4004 - ReactCurrentActQueue.current === null
4002 + ReactSharedInternals.actQueue === null
4003 ) {
4004 console.error(
4005 'A suspended resource finished loading inside a test, but the event ' +
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
+26 -36
@@ -948,14 +948,13 @@ describe('ReactHooks', () => {
948
949 it('warns when reading context inside useMemo', async () => {
950 const {useMemo, createContext} = React;
951 - const ReactCurrentDispatcher =
952 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
953 - .ReactCurrentDispatcher;
951 + const ReactSharedInternals =
952 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
953
954 const ThemeContext = createContext('light');
955 function App() {
956 return useMemo(() => {
958 - return ReactCurrentDispatcher.current.readContext(ThemeContext);
957 + return ReactSharedInternals.H.readContext(ThemeContext);
958 }, []);
959 }
960
@@ -968,18 +967,17 @@ describe('ReactHooks', () => {
967
968 it('warns when reading context inside useMemo after reading outside it', async () => {
969 const {useMemo, createContext} = React;
971 - const ReactCurrentDispatcher =
972 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
973 - .ReactCurrentDispatcher;
970 + const ReactSharedInternals =
971 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
972
973 const ThemeContext = createContext('light');
974 let firstRead, secondRead;
975 function App() {
978 - firstRead = ReactCurrentDispatcher.current.readContext(ThemeContext);
976 + firstRead = ReactSharedInternals.H.readContext(ThemeContext);
977 useMemo(() => {});
980 - secondRead = ReactCurrentDispatcher.current.readContext(ThemeContext);
978 + secondRead = ReactSharedInternals.H.readContext(ThemeContext);
979 return useMemo(() => {
982 - return ReactCurrentDispatcher.current.readContext(ThemeContext);
980 + return ReactSharedInternals.H.readContext(ThemeContext);
981 }, []);
982 }
983
@@ -995,14 +993,13 @@ describe('ReactHooks', () => {
993 // Throws because there's no runtime cost for being strict here.
994 it('throws when reading context inside useEffect', async () => {
995 const {useEffect, createContext} = React;
998 - const ReactCurrentDispatcher =
999 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1000 - .ReactCurrentDispatcher;
996 + const ReactSharedInternals =
997 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
998
999 const ThemeContext = createContext('light');
1000 function App() {
1001 useEffect(() => {
1005 - ReactCurrentDispatcher.current.readContext(ThemeContext);
1002 + ReactSharedInternals.H.readContext(ThemeContext);
1003 });
1004 return null;
1005 }
@@ -1017,14 +1014,13 @@ describe('ReactHooks', () => {
1014 // Throws because there's no runtime cost for being strict here.
1015 it('throws when reading context inside useLayoutEffect', async () => {
1016 const {useLayoutEffect, createContext} = React;
1020 - const ReactCurrentDispatcher =
1021 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1022 - .ReactCurrentDispatcher;
1017 + const ReactSharedInternals =
1018 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1019
1020 const ThemeContext = createContext('light');
1021 function App() {
1022 useLayoutEffect(() => {
1027 - ReactCurrentDispatcher.current.readContext(ThemeContext);
1023 + ReactSharedInternals.H.readContext(ThemeContext);
1024 });
1025 return null;
1026 }
@@ -1041,14 +1037,13 @@ describe('ReactHooks', () => {
1037
1038 it('warns when reading context inside useReducer', async () => {
1039 const {useReducer, createContext} = React;
1044 - const ReactCurrentDispatcher =
1045 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1046 - .ReactCurrentDispatcher;
1040 + const ReactSharedInternals =
1041 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1042
1043 const ThemeContext = createContext('light');
1044 function App() {
1045 const [state, dispatch] = useReducer((s, action) => {
1051 - ReactCurrentDispatcher.current.readContext(ThemeContext);
1046 + ReactSharedInternals.H.readContext(ThemeContext);
1047 return action;
1048 }, 0);
1049 if (state === 0) {
@@ -1069,9 +1064,8 @@ describe('ReactHooks', () => {
1064 const {useState, createContext} = React;
1065 const ThemeContext = createContext('light');
1066
1072 - const ReactCurrentDispatcher =
1073 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1074 - .ReactCurrentDispatcher;
1067 + const ReactSharedInternals =
1068 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1069
1070 let _setState;
1071 function Fn() {
@@ -1082,9 +1076,7 @@ describe('ReactHooks', () => {
1076
1077 class Cls extends React.Component {
1078 render() {
1085 - _setState(() =>
1086 - ReactCurrentDispatcher.current.readContext(ThemeContext),
1087 - );
1079 + _setState(() => ReactSharedInternals.H.readContext(ThemeContext));
1080
1081 return null;
1082 }
@@ -1162,15 +1154,14 @@ describe('ReactHooks', () => {
1154 });
1155
1156 it('resets warning internal state when interrupted by an error', async () => {
1165 - const ReactCurrentDispatcher =
1166 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1167 - .ReactCurrentDispatcher;
1157 + const ReactSharedInternals =
1158 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1159
1160 const ThemeContext = React.createContext('light');
1161 function App() {
1162 React.useMemo(() => {
1163 // Trigger warnings
1173 - ReactCurrentDispatcher.current.readContext(ThemeContext);
1164 + ReactSharedInternals.H.readContext(ThemeContext);
1165 React.useRef();
1166 // Interrupt exit from a Hook
1167 throw new Error('No.');
@@ -1251,14 +1242,13 @@ describe('ReactHooks', () => {
1242
1243 it('warns when reading context inside useMemo', async () => {
1244 const {useMemo, createContext} = React;
1254 - const ReactCurrentDispatcher =
1255 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
1256 - .ReactCurrentDispatcher;
1245 + const ReactSharedInternals =
1246 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1247
1248 const ThemeContext = createContext('light');
1249 function App() {
1250 return useMemo(() => {
1261 - return ReactCurrentDispatcher.current.readContext(ThemeContext);
1251 + return ReactSharedInternals.H.readContext(ThemeContext);
1252 }, []);
1253 }
1254
packages/react-reconciler/src/__tests__/ReactMemo-test.js
+1 -2
@@ -138,8 +138,7 @@ describe('memo', () => {
138
139 function readContext(Context) {
140 const dispatcher =
141 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
142 - .ReactCurrentDispatcher.current;
141 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.H;
142 return dispatcher.readContext(Context);
143 }
144
packages/react-reconciler/src/__tests__/ReactNewContext-test.js
+1 -2
@@ -49,8 +49,7 @@ describe('ReactNewContext', () => {
49
50 function readContext(Context) {
51 const dispatcher =
52 - React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
53 - .ReactCurrentDispatcher.current;
52 + React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.H;
53 return dispatcher.readContext(Context);
54 }
55
packages/react-server-dom-turbopack/src/ReactFlightTurbopackNodeRegister.js
+1 -1
@@ -44,7 +44,7 @@ module.exports = function register() {
44 }).body;
45 } catch (x) {
46 // eslint-disable-next-line react-internal/no-production-logging
47 - console.error('Error parsing %s %s', url, x.message);
47 + console['error']('Error parsing %s %s', url, x.message);
48 return originalCompile.apply(this, arguments);
49 }
50
packages/react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js
+1 -1
@@ -44,7 +44,7 @@ module.exports = function register() {
44 }).body;
45 } catch (x) {
46 // eslint-disable-next-line react-internal/no-production-logging
47 - console.error('Error parsing %s %s', url, x.message);
47 + console['error']('Error parsing %s %s', url, x.message);
48 return originalCompile.apply(this, arguments);
49 }
50
packages/react-server/src/ReactFizzServer.js
+11 -15
@@ -152,10 +152,6 @@ import isArray from 'shared/isArray';
152 import {SuspenseException, getSuspendedThenable} from './ReactFizzThenable';
153 import type {Postpone} from 'react/src/ReactPostpone';
154
155 -const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
156 -const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
157 -const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
158 -
155 // Linked list representing the identity of a component given the component/tag name and key.
156 // The name might be minified but we assume that it's going to be the same generated name. Typically
157 // because it's just the same compiled output in practice.
@@ -3665,21 +3661,21 @@ export function performWork(request: Request): void {
3661 return;
3662 }
3663 const prevContext = getActiveContext();
3668 - const prevDispatcher = ReactCurrentDispatcher.current;
3669 - ReactCurrentDispatcher.current = HooksDispatcher;
3670 - let prevCacheDispatcher;
3664 + const prevDispatcher = ReactSharedInternals.H;
3665 + ReactSharedInternals.H = HooksDispatcher;
3666 + let prevCacheDispatcher = null;
3667 if (enableCache) {
3672 - prevCacheDispatcher = ReactCurrentCache.current;
3673 - ReactCurrentCache.current = DefaultCacheDispatcher;
3668 + prevCacheDispatcher = ReactSharedInternals.C;
3669 + ReactSharedInternals.C = DefaultCacheDispatcher;
3670 }
3671
3672 const prevRequest = currentRequest;
3673 currentRequest = request;
3674
3679 - let prevGetCurrentStackImpl;
3675 + let prevGetCurrentStackImpl = null;
3676 if (__DEV__) {
3681 - prevGetCurrentStackImpl = ReactDebugCurrentFrame.getCurrentStack;
3682 - ReactDebugCurrentFrame.getCurrentStack = getCurrentStackInDEV;
3677 + prevGetCurrentStackImpl = ReactSharedInternals.getCurrentStack;
3678 + ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
3679 }
3680 const prevResumableState = currentResumableState;
3681 setCurrentResumableState(request.resumableState);
@@ -3700,13 +3696,13 @@ export function performWork(request: Request): void {
3696 fatalError(request, error);
3697 } finally {
3698 setCurrentResumableState(prevResumableState);
3703 - ReactCurrentDispatcher.current = prevDispatcher;
3699 + ReactSharedInternals.H = prevDispatcher;
3700 if (enableCache) {
3705 - ReactCurrentCache.current = prevCacheDispatcher;
3701 + ReactSharedInternals.C = prevCacheDispatcher;
3702 }
3703
3704 if (__DEV__) {
3709 - ReactDebugCurrentFrame.getCurrentStack = prevGetCurrentStackImpl;
3705 + ReactSharedInternals.getCurrentStack = prevGetCurrentStackImpl;
3706 }
3707 if (prevDispatcher === HooksDispatcher) {
3708 // This means that we were in a reentrant work loop. This could happen
packages/react-server/src/ReactFlightServer.js
+13 -15
@@ -108,8 +108,9 @@ import {
108 objectName,
109 } from 'shared/ReactSerializationErrors';
110
111 -import ReactSharedInternals from 'shared/ReactSharedInternals';
112 -import ReactServerSharedInternals from './ReactServerSharedInternals';
111 +import type {SharedStateServer} from 'react/src/ReactSharedInternalsServer';
112 +import ReactSharedInternalsImpl from 'shared/ReactSharedInternals';
113 +const ReactSharedInternals: SharedStateServer = (ReactSharedInternalsImpl: any);
114 import isArray from 'shared/isArray';
115 import getPrototypeOf from 'shared/getPrototypeOf';
116 import binaryToComparableString from 'shared/binaryToComparableString';
@@ -154,7 +155,7 @@ function patchConsole(consoleInst: typeof console, methodName: string) {
155 // We don't currently use this id for anything but we emit it so that we can later
156 // refer to previous logs in debug info to associate them with a component.
157 const id = request.nextChunkId++;
157 - const owner: null | ReactComponentInfo = ReactCurrentOwner.current;
158 + const owner: null | ReactComponentInfo = ReactSharedInternals.owner;
159 emitConsoleChunk(request, id, methodName, owner, stack, arguments);
160 }
161 // $FlowFixMe[prop-missing]
@@ -305,10 +306,7 @@ const {
306 TaintRegistryValues,
307 TaintRegistryByteLengths,
308 TaintRegistryPendingRequests,
308 - ReactCurrentCache,
309 -} = ReactServerSharedInternals;
310 -const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
311 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
309 +} = ReactSharedInternals;
310
311 function throwTaintViolation(message: string) {
312 // eslint-disable-next-line react-internal/prod-error-codes
@@ -354,14 +352,14 @@ export function createRequest(
352 environmentName: void | string,
353 ): Request {
354 if (
357 - ReactCurrentCache.current !== null &&
358 - ReactCurrentCache.current !== DefaultCacheDispatcher
355 + ReactSharedInternals.C !== null &&
356 + ReactSharedInternals.C !== DefaultCacheDispatcher
357 ) {
358 throw new Error(
359 'Currently React only supports one RSC renderer at a time.',
360 );
361 }
364 - ReactCurrentCache.current = DefaultCacheDispatcher;
362 + ReactSharedInternals.C = DefaultCacheDispatcher;
363
364 const abortSet: Set<Task> = new Set();
365 const pingedTasks: Array<Task> = [];
@@ -644,11 +642,11 @@ function renderFunctionComponent<Props>(
642 const secondArg = undefined;
643 let result;
644 if (__DEV__) {
647 - ReactCurrentOwner.current = componentDebugInfo;
645 + ReactSharedInternals.owner = componentDebugInfo;
646 try {
647 result = Component(props, secondArg);
648 } finally {
651 - ReactCurrentOwner.current = null;
649 + ReactSharedInternals.owner = null;
650 }
651 } else {
652 result = Component(props, secondArg);
@@ -2492,8 +2490,8 @@ function retryTask(request: Request, task: Task): void {
2490 }
2491
2492 function performWork(request: Request): void {
2495 - const prevDispatcher = ReactCurrentDispatcher.current;
2496 - ReactCurrentDispatcher.current = HooksDispatcher;
2493 + const prevDispatcher = ReactSharedInternals.H;
2494 + ReactSharedInternals.H = HooksDispatcher;
2495 const prevRequest = currentRequest;
2496 currentRequest = request;
2497 prepareToUseHooksForRequest(request);
@@ -2512,7 +2510,7 @@ function performWork(request: Request): void {
2510 logRecoverableError(request, error);
2511 fatalError(request, error);
2512 } finally {
2515 - ReactCurrentDispatcher.current = prevDispatcher;
2513 + ReactSharedInternals.H = prevDispatcher;
2514 resetHooksForRequest();
2515 currentRequest = prevRequest;
2516 }
packages/react-server/src/ReactServerSharedInternals.js deleted
-24
@@ -1,24 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import * as React from 'react';
11 -
12 -const ReactSharedServerInternals =
13 - // $FlowFixMe: It's defined in the one we resolve to.
14 - React.__SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
15 -
16 -if (!ReactSharedServerInternals) {
17 - throw new Error(
18 - 'The "react" package in this environment is not configured correctly. ' +
19 - 'The "react-server" condition must be enabled in any environment that ' +
20 - 'runs React Server Components.',
21 - );
22 -}
23 -
24 -export default ReactSharedServerInternals;
packages/react-suspense-test-utils/src/ReactSuspenseTestUtils.js
+3 -5
@@ -10,8 +10,6 @@
10 import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 import ReactSharedInternals from 'shared/ReactSharedInternals';
12
13 -const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
14 -
13 export function waitForSuspense<T>(fn: () => T): Promise<T> {
14 const cache: Map<Function, mixed> = new Map();
15 const testDispatcher: CacheDispatcher = {
@@ -28,8 +26,8 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
26 // Not using async/await because we don't compile it.
27 return new Promise((resolve, reject) => {
28 function retry() {
31 - const prevDispatcher = ReactCurrentCache.current;
32 - ReactCurrentCache.current = testDispatcher;
29 + const prevDispatcher = ReactSharedInternals.C;
30 + ReactSharedInternals.C = testDispatcher;
31 try {
32 const result = fn();
33 resolve(result);
@@ -40,7 +38,7 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
38 reject(thrownValue);
39 }
40 } finally {
43 - ReactCurrentCache.current = prevDispatcher;
41 + ReactSharedInternals.C = prevDispatcher;
42 }
43 }
44 retry();
packages/react/src/ReactAct.js
+36 -36
@@ -8,8 +8,8 @@
8 */
9
10 import type {Thenable} from 'shared/ReactTypes';
11 -import type {RendererTask} from './ReactCurrentActQueue';
12 -import ReactCurrentActQueue from './ReactCurrentActQueue';
11 +import type {RendererTask} from './ReactSharedInternalsClient';
12 +import ReactSharedInternals from './ReactSharedInternalsClient';
13 import queueMacrotask from 'shared/enqueueTask';
14
15 import {disableLegacyMode} from 'shared/ReactFeatureFlags';
@@ -31,7 +31,7 @@ function aggregateErrors(errors: Array<mixed>): mixed {
31
32 export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
33 if (__DEV__) {
34 - // When ReactCurrentActQueue.current is not null, it signals to React that
34 + // When ReactSharedInternals.actQueue is not null, it signals to React that
35 // we're currently inside an `act` scope. React will push all its tasks to
36 // this queue instead of scheduling them with platform APIs.
37 //
@@ -41,19 +41,19 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
41 //
42 // If we're already inside an `act` scope, reuse the existing queue.
43 const prevIsBatchingLegacy = !disableLegacyMode
44 - ? ReactCurrentActQueue.isBatchingLegacy
44 + ? ReactSharedInternals.isBatchingLegacy
45 : false;
46 - const prevActQueue = ReactCurrentActQueue.current;
46 + const prevActQueue = ReactSharedInternals.actQueue;
47 const prevActScopeDepth = actScopeDepth;
48 actScopeDepth++;
49 - const queue = (ReactCurrentActQueue.current =
49 + const queue = (ReactSharedInternals.actQueue =
50 prevActQueue !== null ? prevActQueue : []);
51 // Used to reproduce behavior of `batchedUpdates` in legacy mode. Only
52 // set to `true` while the given callback is executed, not for updates
53 // triggered during an async event, because this is how the legacy
54 // implementation of `act` behaved.
55 if (!disableLegacyMode) {
56 - ReactCurrentActQueue.isBatchingLegacy = true;
56 + ReactSharedInternals.isBatchingLegacy = true;
57 }
58
59 let result;
@@ -65,11 +65,11 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
65 // only place we ever read this fields is just below, right after running
66 // the callback. So we don't need to reset after the callback runs.
67 if (!disableLegacyMode) {
68 - ReactCurrentActQueue.didScheduleLegacyUpdate = false;
68 + ReactSharedInternals.didScheduleLegacyUpdate = false;
69 }
70 result = callback();
71 const didScheduleLegacyUpdate = !disableLegacyMode
72 - ? ReactCurrentActQueue.didScheduleLegacyUpdate
72 + ? ReactSharedInternals.didScheduleLegacyUpdate
73 : false;
74
75 // Replicate behavior of original `act` implementation in legacy mode,
@@ -83,22 +83,22 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
83 // that's how it worked before version 18. Yes, it's confusing! We should
84 // delete legacy mode!!
85 if (!disableLegacyMode) {
86 - ReactCurrentActQueue.isBatchingLegacy = prevIsBatchingLegacy;
86 + ReactSharedInternals.isBatchingLegacy = prevIsBatchingLegacy;
87 }
88 } catch (error) {
89 // `isBatchingLegacy` gets reset using the regular stack, not the async
90 // one used to track `act` scopes. Why, you may be wondering? Because
91 // that's how it worked before version 18. Yes, it's confusing! We should
92 // delete legacy mode!!
93 - ReactCurrentActQueue.thrownErrors.push(error);
93 + ReactSharedInternals.thrownErrors.push(error);
94 }
95 - if (ReactCurrentActQueue.thrownErrors.length > 0) {
95 + if (ReactSharedInternals.thrownErrors.length > 0) {
96 if (!disableLegacyMode) {
97 - ReactCurrentActQueue.isBatchingLegacy = prevIsBatchingLegacy;
97 + ReactSharedInternals.isBatchingLegacy = prevIsBatchingLegacy;
98 }
99 popActScope(prevActQueue, prevActScopeDepth);
100 - const thrownError = aggregateErrors(ReactCurrentActQueue.thrownErrors);
101 - ReactCurrentActQueue.thrownErrors.length = 0;
100 + const thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
101 + ReactSharedInternals.thrownErrors.length = 0;
102 throw thrownError;
103 }
104
@@ -149,13 +149,13 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
149 // `thenable` might not be a real promise, and `flushActQueue`
150 // might throw, so we need to wrap `flushActQueue` in a
151 // try/catch.
152 - ReactCurrentActQueue.thrownErrors.push(error);
152 + ReactSharedInternals.thrownErrors.push(error);
153 }
154 - if (ReactCurrentActQueue.thrownErrors.length > 0) {
154 + if (ReactSharedInternals.thrownErrors.length > 0) {
155 const thrownError = aggregateErrors(
156 - ReactCurrentActQueue.thrownErrors,
156 + ReactSharedInternals.thrownErrors,
157 );
158 - ReactCurrentActQueue.thrownErrors.length = 0;
158 + ReactSharedInternals.thrownErrors.length = 0;
159 reject(thrownError);
160 }
161 } else {
@@ -164,11 +164,11 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
164 },
165 error => {
166 popActScope(prevActQueue, prevActScopeDepth);
167 - if (ReactCurrentActQueue.thrownErrors.length > 0) {
167 + if (ReactSharedInternals.thrownErrors.length > 0) {
168 const thrownError = aggregateErrors(
169 - ReactCurrentActQueue.thrownErrors,
169 + ReactSharedInternals.thrownErrors,
170 );
171 - ReactCurrentActQueue.thrownErrors.length = 0;
171 + ReactSharedInternals.thrownErrors.length = 0;
172 reject(thrownError);
173 } else {
174 reject(error);
@@ -222,12 +222,12 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
222 //
223 // TODO: In a future version, consider always requiring all `act` calls
224 // to be awaited, regardless of whether the callback is sync or async.
225 - ReactCurrentActQueue.current = null;
225 + ReactSharedInternals.actQueue = null;
226 }
227
228 - if (ReactCurrentActQueue.thrownErrors.length > 0) {
229 - const thrownError = aggregateErrors(ReactCurrentActQueue.thrownErrors);
230 - ReactCurrentActQueue.thrownErrors.length = 0;
228 + if (ReactSharedInternals.thrownErrors.length > 0) {
229 + const thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
230 + ReactSharedInternals.thrownErrors.length = 0;
231 throw thrownError;
232 }
233
@@ -237,7 +237,7 @@ export function act<T>(callback: () => T | Thenable<T>): Thenable<T> {
237 if (prevActScopeDepth === 0) {
238 // If the `act` call is awaited, restore the queue we were
239 // using before (see long comment above) so we can flush it.
240 - ReactCurrentActQueue.current = queue;
240 + ReactSharedInternals.actQueue = queue;
241 queueMacrotask(() =>
242 // Recursively flush tasks scheduled by a microtask.
243 recursivelyFlushAsyncActWork(returnValue, resolve, reject),
@@ -275,7 +275,7 @@ function recursivelyFlushAsyncActWork<T>(
275 ) {
276 if (__DEV__) {
277 // Check if any tasks were scheduled asynchronously.
278 - const queue = ReactCurrentActQueue.current;
278 + const queue = ReactSharedInternals.actQueue;
279 if (queue !== null) {
280 if (queue.length !== 0) {
281 // Async tasks were scheduled, mostly likely in a microtask.
@@ -290,16 +290,16 @@ function recursivelyFlushAsyncActWork<T>(
290 return;
291 } catch (error) {
292 // Leave remaining tasks on the queue if something throws.
293 - ReactCurrentActQueue.thrownErrors.push(error);
293 + ReactSharedInternals.thrownErrors.push(error);
294 }
295 } else {
296 // The queue is empty. We can finish.
297 - ReactCurrentActQueue.current = null;
297 + ReactSharedInternals.actQueue = null;
298 }
299 }
300 - if (ReactCurrentActQueue.thrownErrors.length > 0) {
301 - const thrownError = aggregateErrors(ReactCurrentActQueue.thrownErrors);
302 - ReactCurrentActQueue.thrownErrors.length = 0;
300 + if (ReactSharedInternals.thrownErrors.length > 0) {
301 + const thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
302 + ReactSharedInternals.thrownErrors.length = 0;
303 reject(thrownError);
304 } else {
305 resolve(returnValue);
@@ -318,10 +318,10 @@ function flushActQueue(queue: Array<RendererTask>) {
318 for (; i < queue.length; i++) {
319 let callback: RendererTask = queue[i];
320 do {
321 - ReactCurrentActQueue.didUsePromise = false;
321 + ReactSharedInternals.didUsePromise = false;
322 const continuation = callback(false);
323 if (continuation !== null) {
324 - if (ReactCurrentActQueue.didUsePromise) {
324 + if (ReactSharedInternals.didUsePromise) {
325 // The component just suspended. Yield to the main thread in
326 // case the promise is already resolved. If so, it will ping in
327 // a microtask and we can resume without unwinding the stack.
@@ -340,7 +340,7 @@ function flushActQueue(queue: Array<RendererTask>) {
340 } catch (error) {
341 // If something throws, leave the remaining callbacks on the queue.
342 queue.splice(0, i + 1);
343 - ReactCurrentActQueue.thrownErrors.push(error);
343 + ReactSharedInternals.thrownErrors.push(error);
344 } finally {
345 isFlushing = false;
346 }
packages/react/src/ReactCacheImpl.js
+2 -2
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -import ReactCurrentCache from './ReactCurrentCache';
10 +import ReactSharedInternals from 'shared/ReactSharedInternals';
11
12 const UNTERMINATED = 0;
13 const TERMINATED = 1;
@@ -54,7 +54,7 @@ function createCacheNode<T>(): CacheNode<T> {
54
55 export function cache<A: Iterable<mixed>, T>(fn: (...A) => T): (...A) => T {
56 return function () {
57 - const dispatcher = ReactCurrentCache.current;
57 + const dispatcher = ReactSharedInternals.C;
58 if (!dispatcher) {
59 // If there is no dispatcher, then we treat this as not being cached.
60 // $FlowFixMe[incompatible-call]: We don't want to use rest arguments since we transpile the code.
packages/react/src/ReactCurrentActQueue.js deleted
-28
@@ -1,28 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -export type RendererTask = boolean => RendererTask | null;
11 -
12 -const ReactCurrentActQueue = {
13 - current: (null: null | Array<RendererTask>),
14 -
15 - // Used to reproduce behavior of `batchedUpdates` in legacy mode.
16 - isBatchingLegacy: false,
17 - didScheduleLegacyUpdate: false,
18 -
19 - // Tracks whether something called `use` during the current batch of work.
20 - // Determines whether we should yield to microtasks to unwrap already resolved
21 - // promises without suspending.
22 - didUsePromise: false,
23 -
24 - // Track first uncaught error within this act
25 - thrownErrors: ([]: Array<mixed>),
26 -};
27 -
28 -export default ReactCurrentActQueue;
packages/react/src/ReactCurrentBatchConfig.js deleted
-23
@@ -1,23 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
11 -
12 -export type BatchConfig = {
13 - transition: BatchConfigTransition | null,
14 -};
15 -/**
16 - * Keeps track of the current batch's configuration such as how long an update
17 - * should suspend for if it needs to.
18 - */
19 -const ReactCurrentBatchConfig: BatchConfig = {
20 - transition: null,
21 -};
22 -
23 -export default ReactCurrentBatchConfig;
packages/react/src/ReactCurrentCache.js deleted
-19
@@ -1,19 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 -
12 -/**
13 - * Keeps track of the current Cache dispatcher.
14 - */
15 -const ReactCurrentCache = {
16 - current: (null: null | CacheDispatcher),
17 -};
18 -
19 -export default ReactCurrentCache;
packages/react/src/ReactCurrentDispatcher.js deleted
-19
@@ -1,19 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 -
12 -/**
13 - * Keeps track of the current dispatcher.
14 - */
15 -const ReactCurrentDispatcher = {
16 - current: (null: null | Dispatcher),
17 -};
18 -
19 -export default ReactCurrentDispatcher;
packages/react/src/ReactCurrentOwner.js deleted
-26
@@ -1,26 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
11 -
12 -/**
13 - * Keeps track of the current owner.
14 - *
15 - * The current owner is the component who should own any components that are
16 - * currently being constructed.
17 - */
18 -const ReactCurrentOwner = {
19 - /**
20 - * @internal
21 - * @type {ReactComponent}
22 - */
23 - current: (null: null | Fiber),
24 -};
25 -
26 -export default ReactCurrentOwner;
packages/react/src/ReactDebugCurrentFrame.js deleted
-51
@@ -1,51 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -const ReactDebugCurrentFrame: {
11 - setExtraStackFrame?: (stack: null | string) => void,
12 - getCurrentStack?: null | (() => string),
13 - getStackAddendum?: () => string,
14 -} = {};
15 -
16 -let currentExtraStackFrame = (null: null | string);
17 -
18 -export function setExtraStackFrame(stack: null | string): void {
19 - if (__DEV__) {
20 - currentExtraStackFrame = stack;
21 - }
22 -}
23 -
24 -if (__DEV__) {
25 - ReactDebugCurrentFrame.setExtraStackFrame = function (stack: null | string) {
26 - if (__DEV__) {
27 - currentExtraStackFrame = stack;
28 - }
29 - };
30 - // Stack implementation injected by the current renderer.
31 - ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string));
32 -
33 - ReactDebugCurrentFrame.getStackAddendum = function (): string {
34 - let stack = '';
35 -
36 - // Add an extra top frame while an element is being validated
37 - if (currentExtraStackFrame) {
38 - stack += currentExtraStackFrame;
39 - }
40 -
41 - // Delegate to the injected renderer-specific implementation
42 - const impl = ReactDebugCurrentFrame.getCurrentStack;
43 - if (impl) {
44 - stack += impl() || '';
45 - }
46 -
47 - return stack;
48 - };
49 -}
50 -
51 -export default ReactDebugCurrentFrame;
packages/react/src/ReactFetch.js
+2 -2
@@ -12,7 +12,7 @@ import {
12 enableFetchInstrumentation,
13 } from 'shared/ReactFeatureFlags';
14
15 -import ReactCurrentCache from './ReactCurrentCache';
15 +import ReactSharedInternals from 'shared/ReactSharedInternals';
16
17 function createFetchCache(): Map<string, Array<any>> {
18 return new Map();
@@ -46,7 +46,7 @@ if (enableCache && enableFetchInstrumentation) {
46 resource: URL | RequestInfo,
47 options?: RequestOptions,
48 ) {
49 - const dispatcher = ReactCurrentCache.current;
49 + const dispatcher = ReactSharedInternals.C;
50 if (!dispatcher) {
51 // We're outside a cached scope.
52 return originalFetch(resource, options);
packages/react/src/ReactHooks.js
+4 -4
@@ -16,15 +16,15 @@ import type {
16 } from 'shared/ReactTypes';
17 import {REACT_CONSUMER_TYPE} from 'shared/ReactSymbols';
18
19 -import ReactCurrentDispatcher from './ReactCurrentDispatcher';
20 -import ReactCurrentCache from './ReactCurrentCache';
19 +import ReactSharedInternals from 'shared/ReactSharedInternals';
20 +
21 import {enableAsyncActions} from 'shared/ReactFeatureFlags';
22
23 type BasicStateAction<S> = (S => S) | S;
24 type Dispatch<A> = A => void;
25
26 function resolveDispatcher() {
27 - const dispatcher = ReactCurrentDispatcher.current;
27 + const dispatcher = ReactSharedInternals.H;
28 if (__DEV__) {
29 if (dispatcher === null) {
30 console.error(
@@ -44,7 +44,7 @@ function resolveDispatcher() {
44 }
45
46 export function getCacheForType<T>(resourceType: () => T): T {
47 - const dispatcher = ReactCurrentCache.current;
47 + const dispatcher = ReactSharedInternals.C;
48 if (!dispatcher) {
49 // If there is no dispatcher, then we treat this as not being cached.
50 return resourceType();
packages/react/src/ReactServer.experimental.js
-2
@@ -12,8 +12,6 @@ import './ReactFetch';
12
13 export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './ReactSharedInternalsServer';
14
15 -export {default as __SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './ReactServerSharedInternals';
16 -
15 import {forEach, map, count, toArray, only} from './ReactChildren';
16 import {
17 REACT_FRAGMENT_TYPE,
packages/react/src/ReactServer.js
-2
@@ -12,8 +12,6 @@ import './ReactFetch';
12
13 export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './ReactSharedInternalsServer';
14
15 -export {default as __SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './ReactServerSharedInternals';
16 -
15 import {forEach, map, count, toArray, only} from './ReactChildren';
16 import {
17 REACT_FRAGMENT_TYPE,
packages/react/src/ReactServerSharedInternals.js deleted
-31
@@ -1,31 +0,0 @@
1 -/**
2 - * Copyright (c) Meta Platforms, Inc. and affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -import ReactCurrentCache from './ReactCurrentCache';
9 -import {
10 - TaintRegistryObjects,
11 - TaintRegistryValues,
12 - TaintRegistryByteLengths,
13 - TaintRegistryPendingRequests,
14 -} from './ReactTaintRegistry';
15 -
16 -import {enableTaint} from 'shared/ReactFeatureFlags';
17 -
18 -const ReactServerSharedInternals = {
19 - ReactCurrentCache,
20 -};
21 -
22 -if (enableTaint) {
23 - ReactServerSharedInternals.TaintRegistryObjects = TaintRegistryObjects;
24 - ReactServerSharedInternals.TaintRegistryValues = TaintRegistryValues;
25 - ReactServerSharedInternals.TaintRegistryByteLengths =
26 - TaintRegistryByteLengths;
27 - ReactServerSharedInternals.TaintRegistryPendingRequests =
28 - TaintRegistryPendingRequests;
29 -}
30 -
31 -export default ReactServerSharedInternals;
packages/react/src/ReactSharedInternalsClient.js
+77 -14
@@ -3,25 +3,88 @@
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 */
9
8 -import ReactCurrentDispatcher from './ReactCurrentDispatcher';
9 -import ReactCurrentCache from './ReactCurrentCache';
10 -import ReactCurrentBatchConfig from './ReactCurrentBatchConfig';
11 -import ReactCurrentActQueue from './ReactCurrentActQueue';
12 -import ReactCurrentOwner from './ReactCurrentOwner';
13 -import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
14 -
15 -const ReactSharedInternals = {
16 - ReactCurrentDispatcher,
17 - ReactCurrentCache,
18 - ReactCurrentBatchConfig,
19 - ReactCurrentOwner,
10 +import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
12 +import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
13 +import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
14 +
15 +import {disableStringRefs} from 'shared/ReactFeatureFlags';
16 +
17 +export type SharedStateClient = {
18 + H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
19 + C: null | CacheDispatcher, // ReactCurrentCache for Cache
20 + T: null | BatchConfigTransition, // ReactCurrentBatchConfig for Transitions
21 +
22 + // DEV-only-ish
23 + owner: null | Fiber, // ReactCurrentOwner is Fiber on the Client, null in Fizz. Flight uses SharedStateServer.
24 +
25 + // ReactCurrentActQueue
26 + actQueue: null | Array<RendererTask>,
27 +
28 + // Used to reproduce behavior of `batchedUpdates` in legacy mode.
29 + isBatchingLegacy: boolean,
30 + didScheduleLegacyUpdate: boolean,
31 +
32 + // Tracks whether something called `use` during the current batch of work.
33 + // Determines whether we should yield to microtasks to unwrap already resolved
34 + // promises without suspending.
35 + didUsePromise: boolean,
36 +
37 + // Track first uncaught error within this act
38 + thrownErrors: Array<mixed>,
39 +
40 + // ReactDebugCurrentFrame
41 + setExtraStackFrame: (stack: null | string) => void,
42 + getCurrentStack: null | (() => string),
43 + getStackAddendum: () => string,
44 };
45
46 +export type RendererTask = boolean => RendererTask | null;
47 +
48 +const ReactSharedInternals: SharedStateClient = ({
49 + H: null,
50 + C: null,
51 + T: null,
52 +}: any);
53 +
54 +if (__DEV__ || !disableStringRefs) {
55 + ReactSharedInternals.owner = null;
56 +}
57 +
58 if (__DEV__) {
23 - ReactSharedInternals.ReactDebugCurrentFrame = ReactDebugCurrentFrame;
24 - ReactSharedInternals.ReactCurrentActQueue = ReactCurrentActQueue;
59 + ReactSharedInternals.actQueue = null;
60 + ReactSharedInternals.isBatchingLegacy = false;
61 + ReactSharedInternals.didScheduleLegacyUpdate = false;
62 + ReactSharedInternals.didUsePromise = false;
63 + ReactSharedInternals.thrownErrors = [];
64 +
65 + let currentExtraStackFrame = (null: null | string);
66 + ReactSharedInternals.setExtraStackFrame = function (stack: null | string) {
67 + currentExtraStackFrame = stack;
68 + };
69 + // Stack implementation injected by the current renderer.
70 + ReactSharedInternals.getCurrentStack = (null: null | (() => string));
71 +
72 + ReactSharedInternals.getStackAddendum = function (): string {
73 + let stack = '';
74 +
75 + // Add an extra top frame while an element is being validated
76 + if (currentExtraStackFrame) {
77 + stack += currentExtraStackFrame;
78 + }
79 +
80 + // Delegate to the injected renderer-specific implementation
81 + const impl = ReactSharedInternals.getCurrentStack;
82 + if (impl) {
83 + stack += impl() || '';
84 + }
85 +
86 + return stack;
87 + };
88 }
89
90 export default ReactSharedInternals;
packages/react/src/ReactSharedInternalsServer.js
+79 -7
@@ -3,19 +3,91 @@
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 */
9
8 -import ReactCurrentDispatcher from './ReactCurrentDispatcher';
9 -import ReactCurrentOwner from './ReactCurrentOwner';
10 -import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
10 +import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
12 +import type {ReactComponentInfo} from 'shared/ReactTypes';
13 +
14 +import type {
15 + Reference,
16 + TaintEntry,
17 + RequestCleanupQueue,
18 +} from './ReactTaintRegistry';
19 +
20 +import {
21 + TaintRegistryObjects,
22 + TaintRegistryValues,
23 + TaintRegistryByteLengths,
24 + TaintRegistryPendingRequests,
25 +} from './ReactTaintRegistry';
26 +
27 +import {disableStringRefs, enableTaint} from 'shared/ReactFeatureFlags';
28 +
29 +export type SharedStateServer = {
30 + H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
31 + C: null | CacheDispatcher, // ReactCurrentCache for Cache
32
12 -const ReactSharedInternals = {
13 - ReactCurrentDispatcher,
14 - ReactCurrentOwner,
33 + // enableTaint
34 + TaintRegistryObjects: WeakMap<Reference, string>,
35 + TaintRegistryValues: Map<string | bigint, TaintEntry>,
36 + TaintRegistryByteLengths: Set<number>,
37 + TaintRegistryPendingRequests: Set<RequestCleanupQueue>,
38 +
39 + // DEV-only-ish
40 + owner: null | ReactComponentInfo, // ReactCurrentOwner is ReactComponentInfo in Flight, null in Fizz. Fiber/Fizz uses SharedStateClient.
41 +
42 + // ReactDebugCurrentFrame
43 + setExtraStackFrame: (stack: null | string) => void,
44 + getCurrentStack: null | (() => string),
45 + getStackAddendum: () => string,
46 };
47
48 +export type RendererTask = boolean => RendererTask | null;
49 +
50 +const ReactSharedInternals: SharedStateServer = ({
51 + H: null,
52 + C: null,
53 +}: any);
54 +
55 +if (enableTaint) {
56 + ReactSharedInternals.TaintRegistryObjects = TaintRegistryObjects;
57 + ReactSharedInternals.TaintRegistryValues = TaintRegistryValues;
58 + ReactSharedInternals.TaintRegistryByteLengths = TaintRegistryByteLengths;
59 + ReactSharedInternals.TaintRegistryPendingRequests =
60 + TaintRegistryPendingRequests;
61 +}
62 +
63 +if (__DEV__ || !disableStringRefs) {
64 + ReactSharedInternals.owner = null;
65 +}
66 +
67 if (__DEV__) {
18 - ReactSharedInternals.ReactDebugCurrentFrame = ReactDebugCurrentFrame;
68 + let currentExtraStackFrame = (null: null | string);
69 + ReactSharedInternals.setExtraStackFrame = function (stack: null | string) {
70 + currentExtraStackFrame = stack;
71 + };
72 + // Stack implementation injected by the current renderer.
73 + ReactSharedInternals.getCurrentStack = (null: null | (() => string));
74 +
75 + ReactSharedInternals.getStackAddendum = function (): string {
76 + let stack = '';
77 +
78 + // Add an extra top frame while an element is being validated
79 + if (currentExtraStackFrame) {
80 + stack += currentExtraStackFrame;
81 + }
82 +
83 + // Delegate to the injected renderer-specific implementation
84 + const impl = ReactSharedInternals.getCurrentStack;
85 + if (impl) {
86 + stack += impl() || '';
87 + }
88 +
89 + return stack;
90 + };
91 }
92
93 export default ReactSharedInternals;
packages/react/src/ReactStartTransition.js
+10 -9
@@ -9,7 +9,8 @@
9 import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
10 import type {StartTransitionOptions} from 'shared/ReactTypes';
11
12 -import ReactCurrentBatchConfig from './ReactCurrentBatchConfig';
12 +import ReactSharedInternals from 'shared/ReactSharedInternals';
13 +
14 import {
15 enableAsyncActions,
16 enableTransitionTracing,
@@ -21,26 +22,26 @@ export function startTransition(
22 scope: () => void,
23 options?: StartTransitionOptions,
24 ) {
24 - const prevTransition = ReactCurrentBatchConfig.transition;
25 + const prevTransition = ReactSharedInternals.T;
26 // Each renderer registers a callback to receive the return value of
27 // the scope function. This is used to implement async actions.
28 const callbacks = new Set<(BatchConfigTransition, mixed) => mixed>();
29 const transition: BatchConfigTransition = {
30 _callbacks: callbacks,
31 };
31 - ReactCurrentBatchConfig.transition = transition;
32 - const currentTransition = ReactCurrentBatchConfig.transition;
32 + ReactSharedInternals.T = transition;
33 + const currentTransition = ReactSharedInternals.T;
34
35 if (__DEV__) {
35 - ReactCurrentBatchConfig.transition._updatedFibers = new Set();
36 + ReactSharedInternals.T._updatedFibers = new Set();
37 }
38
39 if (enableTransitionTracing) {
40 if (options !== undefined && options.name !== undefined) {
41 // $FlowFixMe[incompatible-use] found when upgrading Flow
41 - ReactCurrentBatchConfig.transition.name = options.name;
42 + ReactSharedInternals.T.name = options.name;
43 // $FlowFixMe[incompatible-use] found when upgrading Flow
43 - ReactCurrentBatchConfig.transition.startTime = -1;
44 + ReactSharedInternals.T.startTime = -1;
45 }
46 }
47
@@ -59,7 +60,7 @@ export function startTransition(
60 reportGlobalError(error);
61 } finally {
62 warnAboutTransitionSubscriptions(prevTransition, currentTransition);
62 - ReactCurrentBatchConfig.transition = prevTransition;
63 + ReactSharedInternals.T = prevTransition;
64 }
65 } else {
66 // When async actions are not enabled, startTransition does not
@@ -68,7 +69,7 @@ export function startTransition(
69 scope();
70 } finally {
71 warnAboutTransitionSubscriptions(prevTransition, currentTransition);
71 - ReactCurrentBatchConfig.transition = prevTransition;
72 + ReactSharedInternals.T = prevTransition;
73 }
74 }
75 }
packages/react/src/ReactTaint.js
+2 -2
@@ -13,13 +13,13 @@ import getPrototypeOf from 'shared/getPrototypeOf';
13
14 import binaryToComparableString from 'shared/binaryToComparableString';
15
16 -import ReactServerSharedInternals from './ReactServerSharedInternals';
16 +import ReactSharedInternals from './ReactSharedInternalsServer';
17 const {
18 TaintRegistryObjects,
19 TaintRegistryValues,
20 TaintRegistryByteLengths,
21 TaintRegistryPendingRequests,
22 -} = ReactServerSharedInternals;
22 +} = ReactSharedInternals;
23
24 interface Reference {}
25
packages/react/src/ReactTaintRegistry.js
+3 -3
@@ -7,9 +7,9 @@
7 * @flow
8 */
9
10 -interface Reference {}
10 +export interface Reference {}
11
12 -type TaintEntry = {
12 +export type TaintEntry = {
13 message: string,
14 count: number,
15 };
@@ -23,5 +23,5 @@ export const TaintRegistryByteLengths: Set<number> = new Set();
23 // When a value is finalized, it means that it has been removed from any global caches.
24 // No future requests can get a handle on it but any ongoing requests can still have
25 // a handle on it. It's still tainted until that happens.
26 -type RequestCleanupQueue = Array<string | bigint>;
26 +export type RequestCleanupQueue = Array<string | bigint>;
27 export const TaintRegistryPendingRequests: Set<RequestCleanupQueue> = new Set();
packages/react/src/forks/ReactSharedInternalsClient.umd.js
+81 -15
@@ -3,21 +3,56 @@
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 */
9
10 +import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11 +import type {CacheDispatcher} from 'react-reconciler/src/ReactInternalTypes';
12 +import type {BatchConfigTransition} from 'react-reconciler/src/ReactFiberTracingMarkerComponent';
13 +import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
14 +
15 import * as Scheduler from 'scheduler';
9 -import ReactCurrentDispatcher from '../ReactCurrentDispatcher';
10 -import ReactCurrentCache from '../ReactCurrentCache';
11 -import ReactCurrentActQueue from '../ReactCurrentActQueue';
12 -import ReactCurrentOwner from '../ReactCurrentOwner';
13 -import ReactDebugCurrentFrame from '../ReactDebugCurrentFrame';
14 -import ReactCurrentBatchConfig from '../ReactCurrentBatchConfig';
15 -
16 -const ReactSharedInternalsClient = {
17 - ReactCurrentDispatcher,
18 - ReactCurrentCache,
19 - ReactCurrentOwner,
20 - ReactCurrentBatchConfig,
16 +
17 +import {disableStringRefs} from 'shared/ReactFeatureFlags';
18 +
19 +export type SharedStateClient = {
20 + H: null | Dispatcher, // ReactCurrentDispatcher for Hooks
21 + C: null | CacheDispatcher, // ReactCurrentCache for Cache
22 + T: null | BatchConfigTransition, // ReactCurrentBatchConfig for Transitions
23 +
24 + // DEV-only-ish
25 + owner?: null | Fiber, // ReactCurrentOwner is Fiber on the Client, null in Fizz. Flight uses SharedStateServer.
26 +
27 + // ReactCurrentActQueue
28 + actQueue?: null | Array<RendererTask>,
29 +
30 + // Used to reproduce behavior of `batchedUpdates` in legacy mode.
31 + isBatchingLegacy?: boolean,
32 + didScheduleLegacyUpdate?: boolean,
33 +
34 + // Tracks whether something called `use` during the current batch of work.
35 + // Determines whether we should yield to microtasks to unwrap already resolved
36 + // promises without suspending.
37 + didUsePromise?: boolean,
38 +
39 + // Track first uncaught error within this act
40 + thrownErrors?: Array<mixed>,
41 +
42 + // ReactDebugCurrentFrame
43 + setExtraStackFrame?: (stack: null | string) => void,
44 + getCurrentStack?: null | (() => string),
45 + getStackAddendum?: () => string,
46 +
47 + Scheduler: any,
48 +};
49 +
50 +export type RendererTask = boolean => RendererTask | null;
51 +
52 +const ReactSharedInternals: SharedStateClient = {
53 + H: null,
54 + C: null,
55 + T: null,
56
57 // Re-export the schedule API(s) for UMD bundles.
58 // This avoids introducing a dependency on a new UMD global in a minor update,
@@ -27,9 +62,40 @@ const ReactSharedInternalsClient = {
62 Scheduler,
63 };
64
65 +if (__DEV__ || !disableStringRefs) {
66 + ReactSharedInternals.owner = null;
67 +}
68 +
69 if (__DEV__) {
31 - ReactSharedInternalsClient.ReactCurrentActQueue = ReactCurrentActQueue;
32 - ReactSharedInternalsClient.ReactDebugCurrentFrame = ReactDebugCurrentFrame;
70 + ReactSharedInternals.actQueue = null;
71 + ReactSharedInternals.isBatchingLegacy = false;
72 + ReactSharedInternals.didScheduleLegacyUpdate = false;
73 + ReactSharedInternals.didUsePromise = false;
74 + ReactSharedInternals.thrownErrors = [];
75 +
76 + let currentExtraStackFrame = (null: null | string);
77 + ReactSharedInternals.setExtraStackFrame = function (stack: null | string) {
78 + currentExtraStackFrame = stack;
79 + };
80 + // Stack implementation injected by the current renderer.
81 + ReactSharedInternals.getCurrentStack = (null: null | (() => string));
82 +
83 + ReactSharedInternals.getStackAddendum = function (): string {
84 + let stack = '';
85 +
86 + // Add an extra top frame while an element is being validated
87 + if (currentExtraStackFrame) {
88 + stack += currentExtraStackFrame;
89 + }
90 +
91 + // Delegate to the injected renderer-specific implementation
92 + const impl = ReactSharedInternals.getCurrentStack;
93 + if (impl) {
94 + stack += impl() || '';
95 + }
96 +
97 + return stack;
98 + };
99 }
100
35 -export default ReactSharedInternalsClient;
101 +export default ReactSharedInternals;
packages/react/src/jsx/ReactJSXElement.js
+19 -22
@@ -27,9 +27,6 @@ import {checkPropStringCoercion} from 'shared/CheckStringCoercion';
27 import {ClassComponent} from 'react-reconciler/src/ReactWorkTags';
28 import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
29
30 -const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
31 -const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
32 -
30 const REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
31
32 let specialPropKeyWarningShown;
@@ -71,12 +68,12 @@ function warnIfStringRefCannotBeAutoConverted(config, self) {
68 if (
69 !disableStringRefs &&
70 typeof config.ref === 'string' &&
74 - ReactCurrentOwner.current &&
71 + ReactSharedInternals.owner &&
72 self &&
76 - ReactCurrentOwner.current.stateNode !== self
73 + ReactSharedInternals.owner.stateNode !== self
74 ) {
75 const componentName = getComponentNameFromType(
79 - ReactCurrentOwner.current.type,
76 + ReactSharedInternals.owner.type,
77 );
78
79 if (!didWarnAboutStringRefs[componentName]) {
@@ -87,7 +84,7 @@ function warnIfStringRefCannotBeAutoConverted(config, self) {
84 'We ask you to manually fix this case by using useRef() or createRef() instead. ' +
85 'Learn more about using refs safely here: ' +
86 'https://react.dev/link/strict-mode-string-ref',
90 - getComponentNameFromType(ReactCurrentOwner.current.type),
87 + getComponentNameFromType(ReactSharedInternals.owner.type),
88 config.ref,
89 );
90 didWarnAboutStringRefs[componentName] = true;
@@ -341,7 +338,7 @@ export function jsxProd(type, config, maybeKey) {
338 if (!enableRefAsProp) {
339 ref = config.ref;
340 if (!disableStringRefs) {
344 - ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
341 + ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
342 }
343 }
344 }
@@ -369,7 +366,7 @@ export function jsxProd(type, config, maybeKey) {
366 if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
367 props.ref = coerceStringRef(
368 config[propName],
372 - ReactCurrentOwner.current,
369 + ReactSharedInternals.owner,
370 type,
371 );
372 } else {
@@ -397,7 +394,7 @@ export function jsxProd(type, config, maybeKey) {
394 ref,
395 undefined,
396 undefined,
400 - ReactCurrentOwner.current,
397 + ReactSharedInternals.owner,
398 props,
399 );
400 }
@@ -573,7 +570,7 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
570 if (!enableRefAsProp) {
571 ref = config.ref;
572 if (!disableStringRefs) {
576 - ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
573 + ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
574 }
575 }
576 if (!disableStringRefs) {
@@ -604,7 +601,7 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
601 if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
602 props.ref = coerceStringRef(
603 config[propName],
607 - ReactCurrentOwner.current,
604 + ReactSharedInternals.owner,
605 type,
606 );
607 } else {
@@ -645,7 +642,7 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
642 ref,
643 self,
644 source,
648 - ReactCurrentOwner.current,
645 + ReactSharedInternals.owner,
646 props,
647 );
648
@@ -729,7 +726,7 @@ export function createElement(type, config, children) {
726 if (!enableRefAsProp) {
727 ref = config.ref;
728 if (!disableStringRefs) {
732 - ref = coerceStringRef(ref, ReactCurrentOwner.current, type);
729 + ref = coerceStringRef(ref, ReactSharedInternals.owner, type);
730 }
731 }
732
@@ -761,7 +758,7 @@ export function createElement(type, config, children) {
758 if (enableRefAsProp && !disableStringRefs && propName === 'ref') {
759 props.ref = coerceStringRef(
760 config[propName],
764 - ReactCurrentOwner.current,
761 + ReactSharedInternals.owner,
762 type,
763 );
764 } else {
@@ -819,7 +816,7 @@ export function createElement(type, config, children) {
816 ref,
817 undefined,
818 undefined,
822 - ReactCurrentOwner.current,
819 + ReactSharedInternals.owner,
820 props,
821 );
822
@@ -876,7 +873,7 @@ export function cloneElement(element, config, children) {
873 ref = coerceStringRef(ref, owner, element.type);
874 }
875 }
879 - owner = ReactCurrentOwner.current;
876 + owner = ReactSharedInternals.owner;
877 }
878 if (hasValidKey(config)) {
879 if (__DEV__) {
@@ -963,8 +960,8 @@ export function cloneElement(element, config, children) {
960
961 function getDeclarationErrorAddendum() {
962 if (__DEV__) {
966 - if (ReactCurrentOwner.current) {
967 - const name = getComponentNameFromType(ReactCurrentOwner.current.type);
963 + if (ReactSharedInternals.owner) {
964 + const name = getComponentNameFromType(ReactSharedInternals.owner.type);
965 if (name) {
966 return '\n\nCheck the render method of `' + name + '`.';
967 }
@@ -1068,7 +1065,7 @@ function validateExplicitKey(element, parentType) {
1065 if (
1066 element &&
1067 element._owner != null &&
1071 - element._owner !== ReactCurrentOwner.current
1068 + element._owner !== ReactSharedInternals.owner
1069 ) {
1070 let ownerName = null;
1071 if (typeof element._owner.tag === 'number') {
@@ -1099,9 +1096,9 @@ function setCurrentlyValidatingElement(element) {
1096 element.type,
1097 owner ? owner.type : null,
1098 );
1102 - ReactDebugCurrentFrame.setExtraStackFrame(stack);
1099 + ReactSharedInternals.setExtraStackFrame(stack);
1100 } else {
1104 - ReactDebugCurrentFrame.setExtraStackFrame(null);
1101 + ReactSharedInternals.setExtraStackFrame(null);
1102 }
1103 }
1104 }
packages/shared/ReactComponentStackFrame.js
+4 -6
@@ -23,8 +23,6 @@ import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
23
24 import ReactSharedInternals from 'shared/ReactSharedInternals';
25
26 -const {ReactCurrentDispatcher} = ReactSharedInternals;
27 -
26 let prefix;
27 export function describeBuiltInComponentFrame(name: string): string {
28 if (enableComponentStackLocations) {
@@ -86,13 +84,13 @@ export function describeNativeComponentFrame(
84 const previousPrepareStackTrace = Error.prepareStackTrace;
85 // $FlowFixMe[incompatible-type] It does accept undefined.
86 Error.prepareStackTrace = undefined;
89 - let previousDispatcher;
87 + let previousDispatcher = null;
88
89 if (__DEV__) {
92 - previousDispatcher = ReactCurrentDispatcher.current;
90 + previousDispatcher = ReactSharedInternals.H;
91 // Set the dispatcher in DEV because this might be call in the render function
92 // for warnings.
95 - ReactCurrentDispatcher.current = null;
93 + ReactSharedInternals.H = null;
94 disableLogs();
95 }
96
@@ -272,7 +270,7 @@ export function describeNativeComponentFrame(
270 } finally {
271 reentry = false;
272 if (__DEV__) {
275 - ReactCurrentDispatcher.current = previousDispatcher;
273 + ReactSharedInternals.H = previousDispatcher;
274 reenableLogs();
275 }
276 Error.prepareStackTrace = previousPrepareStackTrace;
packages/shared/consoleWithStackDev.js
+1 -2
@@ -40,8 +40,7 @@ function printWarning(level, format, args) {
40 // When changing this logic, you might want to also
41 // update consoleWithStackDev.www.js as well.
42 if (__DEV__) {
43 - const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
44 - const stack = ReactDebugCurrentFrame.getStackAddendum();
43 + const stack = ReactSharedInternals.getStackAddendum();
44 if (stack !== '') {
45 format += '%s';
46 args = args.concat([stack]);
packages/shared/forks/Scheduler.umd.js
+1 -1
@@ -36,7 +36,7 @@ const {
36 unstable_flushAllWithoutAsserting,
37 log,
38 unstable_setDisableYieldValue,
39 -} = ReactInternals.Scheduler;
39 +} = ((ReactInternals: any).Scheduler: any);
40
41 export {
42 unstable_cancelCallback,
packages/shared/forks/consoleWithStackDev.www.js
+1 -3
@@ -38,9 +38,7 @@ function printWarning(level, format, args) {
38 React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
39 // Defensive in case this is fired before React is initialized.
40 if (ReactSharedInternals != null) {
41 - const ReactDebugCurrentFrame =
42 - ReactSharedInternals.ReactDebugCurrentFrame;
43 - const stack = ReactDebugCurrentFrame.getStackAddendum();
41 + const stack = ReactSharedInternals.getStackAddendum();
42 if (stack !== '') {
43 format += '%s';
44 args.push(stack);
scripts/jest/setupHostConfigs.js
+16 -5
@@ -46,6 +46,11 @@ function mockReact() {
46 );
47 return jest.requireActual(resolvedEntryPoint);
48 });
49 + // Make it possible to import this module inside
50 + // the React package itself.
51 + jest.mock('shared/ReactSharedInternals', () => {
52 + return jest.requireActual('react/src/ReactSharedInternalsClient');
53 + });
54 }
55
56 // When we want to unmock React we really need to mock it again.
@@ -54,6 +59,10 @@ global.__unmockReact = mockReact;
59 mockReact();
60
61 jest.mock('react/react.react-server', () => {
62 + // If we're requiring an RSC environment, use those internals instead.
63 + jest.mock('shared/ReactSharedInternals', () => {
64 + return jest.requireActual('react/src/ReactSharedInternalsServer');
65 + });
66 const resolvedEntryPoint = resolveEntryFork(
67 require.resolve('react/src/ReactServer'),
68 global.__WWW__
@@ -161,11 +170,13 @@ inlinedHostConfigs.forEach(rendererInfo => {
170 });
171 });
172
164 -// Make it possible to import this module inside
165 -// the React package itself.
166 -jest.mock('shared/ReactSharedInternals', () =>
167 - jest.requireActual('react/src/ReactSharedInternalsClient')
168 -);
173 +jest.mock('react-server/src/ReactFlightServer', () => {
174 + // If we're requiring an RSC environment, use those internals instead.
175 + jest.mock('shared/ReactSharedInternals', () => {
176 + return jest.requireActual('react/src/ReactSharedInternalsServer');
177 + });
178 + return jest.requireActual('react-server/src/ReactFlightServer');
179 +});
180
181 // Make it possible to import this module inside
182 // the ReactDOM package itself.