Skip to content

Commit 5a943b2

Browse files
committed
[Devtools] Ensure initial read of useFormStatus returns NotPendingTransition
1 parent 274e1cc commit 5a943b2

File tree

11 files changed

+73
-36
lines changed

11 files changed

+73
-36
lines changed

packages/react-art/src/ReactFiberConfigART.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ import {
1717
NoEventPriority,
1818
} from 'react-reconciler/src/ReactEventPriorities';
1919

20+
import type {ReactContext} from 'shared/ReactTypes';
21+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
22+
2023
const pooledTransform = new Transform();
2124

2225
const NO_CONTEXT = {};
2326
if (__DEV__) {
2427
Object.freeze(NO_CONTEXT);
2528
}
2629

30+
export type TransitionStatus = mixed;
31+
2732
/** Helper Methods */
2833

2934
function addEventListeners(instance, type, listener) {
@@ -490,4 +495,12 @@ export function waitForCommitToBeReady() {
490495
}
491496

492497
export const NotPendingTransition = null;
498+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
499+
$$typeof: REACT_CONTEXT_TYPE,
500+
Provider: (null: any),
501+
Consumer: (null: any),
502+
_currentValue: NotPendingTransition,
503+
_currentValue2: NotPendingTransition,
504+
_threadCount: 0,
505+
};
493506
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 {
@@ -31,6 +31,7 @@ import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostCo
3131

3232
import hasOwnProperty from 'shared/hasOwnProperty';
3333
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
34+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
3435

3536
export {
3637
setCurrentUpdatePriority,
@@ -3460,6 +3461,14 @@ function insertStylesheetIntoRoot(
34603461
}
34613462

34623463
export const NotPendingTransition: TransitionStatus = NotPending;
3464+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
3465+
$$typeof: REACT_CONTEXT_TYPE,
3466+
Provider: (null: any),
3467+
Consumer: (null: any),
3468+
_currentValue: NotPendingTransition,
3469+
_currentValue2: NotPendingTransition,
3470+
_threadCount: 0,
3471+
};
34633472

34643473
export type FormInstance = HTMLFormElement;
34653474
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
@@ -49,6 +49,8 @@ const {
4949
} = nativeFabricUIManager;
5050

5151
import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags';
52+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
53+
import type {ReactContext} from 'shared/ReactTypes';
5254

5355
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
5456

@@ -514,6 +516,14 @@ export function waitForCommitToBeReady(): null {
514516
}
515517

516518
export const NotPendingTransition: TransitionStatus = null;
519+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
520+
$$typeof: REACT_CONTEXT_TYPE,
521+
Provider: (null: any),
522+
Consumer: (null: any),
523+
_currentValue: NotPendingTransition,
524+
_currentValue2: NotPendingTransition,
525+
_threadCount: 0,
526+
};
517527

518528
export type FormInstance = Instance;
519529
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
@@ -31,6 +31,9 @@ import {
3131
} from 'react-reconciler/src/ReactEventPriorities';
3232
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
3333

34+
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
35+
import type {ReactContext} from 'shared/ReactTypes';
36+
3437
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
3538

3639
export type Type = string;
@@ -549,6 +552,14 @@ export function waitForCommitToBeReady(): null {
549552
}
550553

551554
export const NotPendingTransition: TransitionStatus = null;
555+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
556+
$$typeof: REACT_CONTEXT_TYPE,
557+
Provider: (null: any),
558+
Consumer: (null: any),
559+
_currentValue: NotPendingTransition,
560+
_currentValue2: NotPendingTransition,
561+
_threadCount: 0,
562+
};
552563

553564
export type FormInstance = Instance;
554565
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
@@ -176,14 +176,14 @@ import {
176176
isPrimaryRenderer,
177177
getResource,
178178
createHoistableInstance,
179+
HostTransitionContext,
179180
} from './ReactFiberConfig';
180181
import type {SuspenseInstance} from './ReactFiberConfig';
181182
import {shouldError, shouldSuspend} from './ReactFiberReconciler';
182183
import {
183184
pushHostContext,
184185
pushHostContainer,
185186
getRootHostContainer,
186-
HostTransitionContext,
187187
} from './ReactFiberHostContext';
188188
import {
189189
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,
@@ -150,7 +151,6 @@ import {
150151
peekEntangledActionThenable,
151152
chainThenableValue,
152153
} from './ReactFiberAsyncAction';
153-
import {HostTransitionContext} from './ReactFiberHostContext';
154154
import {requestTransitionLane} from './ReactFiberRootScheduler';
155155
import {isCurrentTreeHidden} from './ReactFiberHiddenContext';
156156
import {
@@ -3100,8 +3100,7 @@ function useHostTransitionStatus(): TransitionStatus {
31003100
if (!enableAsyncActions) {
31013101
throw new Error('Not implemented.');
31023102
}
3103-
const status: TransitionStatus | null = readContext(HostTransitionContext);
3104-
return status !== null ? status : NoPendingHostTransition;
3103+
return readContext(HostTransitionContext);
31053104
}
31063105

31073106
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 allowd 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
@@ -19,7 +19,7 @@ import type {SharedQueue} from './ReactFiberClassUpdateQueue';
1919
import type {TransitionStatus} from './ReactFiberConfig';
2020
import type {Hook} from './ReactFiberHooks';
2121

22-
import {isPrimaryRenderer} from './ReactFiberConfig';
22+
import {isPrimaryRenderer, HostTransitionContext} from './ReactFiberConfig';
2323
import {createCursor, push, pop} from './ReactFiberStack';
2424
import {
2525
ContextProvider,
@@ -47,10 +47,7 @@ import {
4747
enableAsyncActions,
4848
enableRenderableContext,
4949
} from 'shared/ReactFeatureFlags';
50-
import {
51-
getHostTransitionProvider,
52-
HostTransitionContext,
53-
} from './ReactFiberHostContext';
50+
import {getHostTransitionProvider} from './ReactFiberHostContext';
5451

5552
const valueCursor: StackCursor<mixed> = createCursor(null);
5653

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const startSuspendingCommit = $$$config.startSuspendingCommit;
7979
export const suspendInstance = $$$config.suspendInstance;
8080
export const waitForCommitToBeReady = $$$config.waitForCommitToBeReady;
8181
export const NotPendingTransition = $$$config.NotPendingTransition;
82+
export const HostTransitionContext = $$$config.HostTransitionContext;
8283
export const resetFormInstance = $$$config.resetFormInstance;
8384

8485
// -------------------

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,
@@ -349,6 +352,14 @@ export function waitForCommitToBeReady(): null {
349352
}
350353

351354
export const NotPendingTransition: TransitionStatus = null;
355+
export const HostTransitionContext: ReactContext<TransitionStatus> = {
356+
$$typeof: REACT_CONTEXT_TYPE,
357+
Provider: (null: any),
358+
Consumer: (null: any),
359+
_currentValue: NotPendingTransition,
360+
_currentValue2: NotPendingTransition,
361+
_threadCount: 0,
362+
};
352363

353364
export type FormInstance = Instance;
354365
export function resetFormInstance(form: Instance): void {}

0 commit comments

Comments
 (0)