Skip to content

Commit f117368

Browse files
committed
[Devtools] Ensure initial read of useFormStatus returns NotPendingTransition
1 parent 106a916 commit f117368

File tree

11 files changed

+72
-36
lines changed

11 files changed

+72
-36
lines changed

packages/react-art/src/ReactFiberConfigART.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
DefaultEventPriority,
1717
NoEventPriority,
1818
} from 'react-reconciler/src/ReactEventPriorities';
19+
import type {ReactContext} from 'shared/ReactTypes';
20+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1921

2022
export {default as rendererVersion} from 'shared/ReactVersion';
2123
export const rendererPackageName = 'react-art';
@@ -28,6 +30,8 @@ if (__DEV__) {
2830
Object.freeze(NO_CONTEXT);
2931
}
3032

33+
export type TransitionStatus = mixed;
34+
3135
/** Helper Methods */
3236

3337
function addEventListeners(instance, type, listener) {
@@ -488,4 +492,12 @@ export function waitForCommitToBeReady() {
488492
}
489493

490494
export const NotPendingTransition = null;
495+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
496+
$$typeof: REACT_CONTEXT_TYPE,
497+
Provider: (null: any),
498+
Consumer: (null: any),
499+
_currentValue: NotPendingTransition,
500+
_currentValue2: NotPendingTransition,
501+
_threadCount: 0,
502+
};
491503
export function resetFormInstance() {}

packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegrationDOM-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ describe('ReactHooksInspectionIntegration', () => {
119119
isStateEditable: false,
120120
name: 'FormStatus',
121121
subHooks: [],
122-
value: null,
122+
value: {
123+
action: null,
124+
data: null,
125+
method: null,
126+
pending: false,
127+
},
123128
},
124129
{
125130
debugInfo: null,

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
IntersectionObserverOptions,
1515
ObserveVisibleRectsCallback,
1616
} from 'react-reconciler/src/ReactTestSelectors';
17-
import type {ReactScopeInstance} from 'shared/ReactTypes';
17+
import type {ReactContext, ReactScopeInstance} from 'shared/ReactTypes';
1818
import type {AncestorInfoDev} from './validateDOMNesting';
1919
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
2020
import type {
@@ -32,6 +32,7 @@ import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostCo
3232

3333
import hasOwnProperty from 'shared/hasOwnProperty';
3434
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
35+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
3536

3637
export {
3738
setCurrentUpdatePriority,
@@ -3564,6 +3565,14 @@ function insertStylesheetIntoRoot(
35643565
}
35653566

35663567
export const NotPendingTransition: TransitionStatus = NotPending;
3568+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
3569+
$$typeof: REACT_CONTEXT_TYPE,
3570+
Provider: (null: any),
3571+
Consumer: (null: any),
3572+
_currentValue: NotPendingTransition,
3573+
_currentValue2: NotPendingTransition,
3574+
_threadCount: 0,
3575+
};
35673576

35683577
export type FormInstance = HTMLFormElement;
35693578
export function resetFormInstance(form: FormInstance): void {

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import {
6060
enableFabricCompleteRootInCommitPhase,
6161
passChildrenWhenCloningPersistedNodes,
6262
} from 'shared/ReactFeatureFlags';
63+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
64+
import type {ReactContext} from 'shared/ReactTypes';
6365

6466
export {default as rendererVersion} from 'shared/ReactVersion'; // TODO: Consider exporting the react-native version.
6567
export const rendererPackageName = 'react-native-renderer';
@@ -544,6 +546,14 @@ export function waitForCommitToBeReady(): null {
544546
}
545547

546548
export const NotPendingTransition: TransitionStatus = null;
549+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
550+
$$typeof: REACT_CONTEXT_TYPE,
551+
Provider: (null: any),
552+
Consumer: (null: any),
553+
_currentValue: NotPendingTransition,
554+
_currentValue2: NotPendingTransition,
555+
_threadCount: 0,
556+
};
547557

548558
export type FormInstance = Instance;
549559
export function resetFormInstance(form: Instance): void {}

packages/react-native-renderer/src/ReactFiberConfigNative.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import {
3232
} from 'react-reconciler/src/ReactEventPriorities';
3333
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
3434

35+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
36+
import type {ReactContext} from 'shared/ReactTypes';
37+
3538
import {
3639
getInspectorDataForViewTag,
3740
getInspectorDataForViewAtPoint,
@@ -561,6 +564,14 @@ export function waitForCommitToBeReady(): null {
561564
}
562565

563566
export const NotPendingTransition: TransitionStatus = null;
567+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
568+
$$typeof: REACT_CONTEXT_TYPE,
569+
Provider: (null: any),
570+
Consumer: (null: any),
571+
_currentValue: NotPendingTransition,
572+
_currentValue2: NotPendingTransition,
573+
_threadCount: 0,
574+
};
564575

565576
export type FormInstance = Instance;
566577
export function resetFormInstance(form: Instance): void {}

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ import {
178178
isPrimaryRenderer,
179179
getResource,
180180
createHoistableInstance,
181+
HostTransitionContext,
181182
} from './ReactFiberConfig';
182183
import type {SuspenseInstance} from './ReactFiberConfig';
183184
import {shouldError, shouldSuspend} from './ReactFiberReconciler';
184185
import {
185186
pushHostContext,
186187
pushHostContainer,
187188
getRootHostContainer,
188-
HostTransitionContext,
189189
} from './ReactFiberHostContext';
190190
import {
191191
suspenseStackCursor,

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {Flags} from './ReactFiberFlags';
2828
import type {TransitionStatus} from './ReactFiberConfig';
2929

3030
import {
31+
HostTransitionContext,
3132
NotPendingTransition as NoPendingHostTransition,
3233
setCurrentUpdatePriority,
3334
getCurrentUpdatePriority,
@@ -156,7 +157,6 @@ import {
156157
peekEntangledActionThenable,
157158
chainThenableValue,
158159
} from './ReactFiberAsyncAction';
159-
import {HostTransitionContext} from './ReactFiberHostContext';
160160
import {requestTransitionLane} from './ReactFiberRootScheduler';
161161
import {isCurrentTreeHidden} from './ReactFiberHiddenContext';
162162
import {requestCurrentTransition} from './ReactFiberTransition';
@@ -3276,8 +3276,7 @@ function useHostTransitionStatus(): TransitionStatus {
32763276
if (!enableAsyncActions) {
32773277
throw new Error('Not implemented.');
32783278
}
3279-
const status: TransitionStatus | null = readContext(HostTransitionContext);
3280-
return status !== null ? status : NoPendingHostTransition;
3279+
return readContext(HostTransitionContext);
32813280
}
32823281

32833282
function mountId(): string {

packages/react-reconciler/src/ReactFiberHostContext.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@
99

1010
import type {Fiber} from './ReactInternalTypes';
1111
import type {StackCursor} from './ReactFiberStack';
12-
import type {
13-
Container,
14-
HostContext,
15-
TransitionStatus,
16-
} from './ReactFiberConfig';
12+
import type {Container, HostContext} from './ReactFiberConfig';
1713
import type {Hook} from './ReactFiberHooks';
18-
import type {ReactContext} from 'shared/ReactTypes';
1914

2015
import {
2116
getChildHostContext,
2217
getRootHostContext,
18+
HostTransitionContext,
19+
NotPendingTransition,
2320
isPrimaryRenderer,
2421
} from './ReactFiberConfig';
2522
import {createCursor, push, pop} from './ReactFiberStack';
26-
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
2723
import {enableAsyncActions} from 'shared/ReactFeatureFlags';
2824

2925
const contextStackCursor: StackCursor<HostContext | null> = createCursor(null);
@@ -38,21 +34,6 @@ const rootInstanceStackCursor: StackCursor<Container | null> =
3834
const hostTransitionProviderCursor: StackCursor<Fiber | null> =
3935
createCursor(null);
4036

41-
// TODO: This should initialize to NotPendingTransition, a constant
42-
// imported from the fiber config. However, because of a cycle in the module
43-
// graph, that value isn't defined during this module's initialization. I can't
44-
// think of a way to work around this without moving that value out of the
45-
// fiber config. For now, the "no provider" case is handled when reading,
46-
// inside useHostTransitionStatus.
47-
export const HostTransitionContext: ReactContext<TransitionStatus | null> = {
48-
$$typeof: REACT_CONTEXT_TYPE,
49-
Provider: (null: any),
50-
Consumer: (null: any),
51-
_currentValue: null,
52-
_currentValue2: null,
53-
_threadCount: 0,
54-
};
55-
5637
function requiredContext<Value>(c: Value | null): Value {
5738
if (__DEV__) {
5839
if (c === null) {
@@ -150,13 +131,13 @@ function popHostContext(fiber: Fiber): void {
150131
pop(hostTransitionProviderCursor, fiber);
151132

152133
// When popping the transition provider, we reset the context value back
153-
// to `null`. We can do this because you're not allowd to nest forms. If
134+
// to `NotPendingTransition`. We can do this because you're not allowed to nest forms. If
154135
// we allowed for multiple nested host transition providers, then we'd
155136
// need to reset this to the parent provider's status.
156137
if (isPrimaryRenderer) {
157-
HostTransitionContext._currentValue = null;
138+
HostTransitionContext._currentValue = NotPendingTransition;
158139
} else {
159-
HostTransitionContext._currentValue2 = null;
140+
HostTransitionContext._currentValue2 = NotPendingTransition;
160141
}
161142
}
162143
}

packages/react-reconciler/src/ReactFiberNewContext.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {SharedQueue} from './ReactFiberClassUpdateQueue';
2020
import type {TransitionStatus} from './ReactFiberConfig';
2121
import type {Hook} from './ReactFiberHooks';
2222

23-
import {isPrimaryRenderer} from './ReactFiberConfig';
23+
import {isPrimaryRenderer, HostTransitionContext} from './ReactFiberConfig';
2424
import {createCursor, push, pop} from './ReactFiberStack';
2525
import {
2626
ContextProvider,
@@ -48,10 +48,7 @@ import {
4848
enableAsyncActions,
4949
enableRenderableContext,
5050
} from 'shared/ReactFeatureFlags';
51-
import {
52-
getHostTransitionProvider,
53-
HostTransitionContext,
54-
} from './ReactFiberHostContext';
51+
import {getHostTransitionProvider} from './ReactFiberHostContext';
5552
import isArray from '../../shared/isArray';
5653
import {enableContextProfiling} from '../../shared/ReactFeatureFlags';
5754

packages/react-reconciler/src/forks/ReactFiberConfig.custom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const startSuspendingCommit = $$$config.startSuspendingCommit;
8383
export const suspendInstance = $$$config.suspendInstance;
8484
export const waitForCommitToBeReady = $$$config.waitForCommitToBeReady;
8585
export const NotPendingTransition = $$$config.NotPendingTransition;
86+
export const HostTransitionContext = $$$config.HostTransitionContext;
8687
export const resetFormInstance = $$$config.resetFormInstance;
8788
export const bindToConsole = $$$config.bindToConsole;
8889

packages/react-test-renderer/src/ReactFiberConfigTestHost.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* @flow
88
*/
99

10+
import type {ReactContext} from 'shared/ReactTypes';
11+
1012
import isArray from 'shared/isArray';
13+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
1114
import {
1215
DefaultEventPriority,
1316
NoEventPriority,
@@ -352,6 +355,14 @@ export function waitForCommitToBeReady(): null {
352355
}
353356

354357
export const NotPendingTransition: TransitionStatus = null;
358+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
359+
$$typeof: REACT_CONTEXT_TYPE,
360+
Provider: (null: any),
361+
Consumer: (null: any),
362+
_currentValue: NotPendingTransition,
363+
_currentValue2: NotPendingTransition,
364+
_threadCount: 0,
365+
};
355366

356367
export type FormInstance = Instance;
357368
export function resetFormInstance(form: Instance): void {}

0 commit comments

Comments
 (0)