Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Devtools] Ensure initial read of useFormStatus returns NotPendingTransition #28728

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/react-art/src/ReactFiberConfigART.js
Expand Up @@ -17,13 +17,18 @@ import {
NoEventPriority,
} from 'react-reconciler/src/ReactEventPriorities';

import type {ReactContext} from 'shared/ReactTypes';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';

const pooledTransform = new Transform();

const NO_CONTEXT = {};
if (__DEV__) {
Object.freeze(NO_CONTEXT);
}

export type TransitionStatus = mixed;

/** Helper Methods */

function addEventListeners(instance, type, listener) {
Expand Down Expand Up @@ -490,4 +495,12 @@ export function waitForCommitToBeReady() {
}

export const NotPendingTransition = null;
export const HostTransitionContext: ReactContext<TransitionStatus> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: NotPendingTransition,
_currentValue2: NotPendingTransition,
_threadCount: 0,
};
export function resetFormInstance() {}
Expand Up @@ -119,7 +119,12 @@ describe('ReactHooksInspectionIntegration', () => {
isStateEditable: false,
name: 'FormStatus',
subHooks: [],
value: null,
value: {
action: null,
data: null,
method: null,
pending: false,
},
},
{
debugInfo: null,
Expand Down
11 changes: 10 additions & 1 deletion packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Expand Up @@ -14,7 +14,7 @@ import type {
IntersectionObserverOptions,
ObserveVisibleRectsCallback,
} from 'react-reconciler/src/ReactTestSelectors';
import type {ReactScopeInstance} from 'shared/ReactTypes';
import type {ReactContext, ReactScopeInstance} from 'shared/ReactTypes';
import type {AncestorInfoDev} from './validateDOMNesting';
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
import type {
Expand All @@ -31,6 +31,7 @@ import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostCo

import hasOwnProperty from 'shared/hasOwnProperty';
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';

export {
setCurrentUpdatePriority,
Expand Down Expand Up @@ -3460,6 +3461,14 @@ function insertStylesheetIntoRoot(
}

export const NotPendingTransition: TransitionStatus = NotPending;
export const HostTransitionContext: ReactContext<TransitionStatus> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: NotPendingTransition,
_currentValue2: NotPendingTransition,
_threadCount: 0,
};

export type FormInstance = HTMLFormElement;
export function resetFormInstance(form: FormInstance): void {
Expand Down
10 changes: 10 additions & 0 deletions packages/react-native-renderer/src/ReactFiberConfigFabric.js
Expand Up @@ -49,6 +49,8 @@ const {
} = nativeFabricUIManager;

import {passChildrenWhenCloningPersistedNodes} from 'shared/ReactFeatureFlags';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
import type {ReactContext} from 'shared/ReactTypes';

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;

Expand Down Expand Up @@ -514,6 +516,14 @@ export function waitForCommitToBeReady(): null {
}

export const NotPendingTransition: TransitionStatus = null;
export const HostTransitionContext: ReactContext<TransitionStatus> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: NotPendingTransition,
_currentValue2: NotPendingTransition,
_threadCount: 0,
};

export type FormInstance = Instance;
export function resetFormInstance(form: Instance): void {}
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native-renderer/src/ReactFiberConfigNative.js
Expand Up @@ -31,6 +31,9 @@ import {
} from 'react-reconciler/src/ReactEventPriorities';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';

import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
import type {ReactContext} from 'shared/ReactTypes';

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;

export type Type = string;
Expand Down Expand Up @@ -549,6 +552,14 @@ export function waitForCommitToBeReady(): null {
}

export const NotPendingTransition: TransitionStatus = null;
export const HostTransitionContext: ReactContext<TransitionStatus> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: NotPendingTransition,
_currentValue2: NotPendingTransition,
_threadCount: 0,
};

export type FormInstance = Instance;
export function resetFormInstance(form: Instance): void {}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberBeginWork.js
Expand Up @@ -176,14 +176,14 @@ import {
isPrimaryRenderer,
getResource,
createHoistableInstance,
HostTransitionContext,
} from './ReactFiberConfig';
import type {SuspenseInstance} from './ReactFiberConfig';
import {shouldError, shouldSuspend} from './ReactFiberReconciler';
import {
pushHostContext,
pushHostContainer,
getRootHostContainer,
HostTransitionContext,
} from './ReactFiberHostContext';
import {
suspenseStackCursor,
Expand Down
5 changes: 2 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.js
Expand Up @@ -28,6 +28,7 @@ import type {Flags} from './ReactFiberFlags';
import type {TransitionStatus} from './ReactFiberConfig';

import {
HostTransitionContext,
NotPendingTransition as NoPendingHostTransition,
setCurrentUpdatePriority,
getCurrentUpdatePriority,
Expand Down Expand Up @@ -150,7 +151,6 @@ import {
peekEntangledActionThenable,
chainThenableValue,
} from './ReactFiberAsyncAction';
import {HostTransitionContext} from './ReactFiberHostContext';
import {requestTransitionLane} from './ReactFiberRootScheduler';
import {isCurrentTreeHidden} from './ReactFiberHiddenContext';
import {
Expand Down Expand Up @@ -3100,8 +3100,7 @@ function useHostTransitionStatus(): TransitionStatus {
if (!enableAsyncActions) {
throw new Error('Not implemented.');
}
const status: TransitionStatus | null = readContext(HostTransitionContext);
return status !== null ? status : NoPendingHostTransition;
return readContext(HostTransitionContext);
}

function mountId(): string {
Expand Down
31 changes: 6 additions & 25 deletions packages/react-reconciler/src/ReactFiberHostContext.js
Expand Up @@ -9,21 +9,17 @@

import type {Fiber} from './ReactInternalTypes';
import type {StackCursor} from './ReactFiberStack';
import type {
Container,
HostContext,
TransitionStatus,
} from './ReactFiberConfig';
import type {Container, HostContext} from './ReactFiberConfig';
import type {Hook} from './ReactFiberHooks';
import type {ReactContext} from 'shared/ReactTypes';

import {
getChildHostContext,
getRootHostContext,
HostTransitionContext,
NotPendingTransition,
isPrimaryRenderer,
} from './ReactFiberConfig';
import {createCursor, push, pop} from './ReactFiberStack';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
import {enableAsyncActions} from 'shared/ReactFeatureFlags';

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

// TODO: This should initialize to NotPendingTransition, a constant
// imported from the fiber config. However, because of a cycle in the module
// graph, that value isn't defined during this module's initialization. I can't
// think of a way to work around this without moving that value out of the
// fiber config. For now, the "no provider" case is handled when reading,
// inside useHostTransitionStatus.
export const HostTransitionContext: ReactContext<TransitionStatus | null> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: null,
_currentValue2: null,
_threadCount: 0,
};

function requiredContext<Value>(c: Value | null): Value {
if (__DEV__) {
if (c === null) {
Expand Down Expand Up @@ -150,13 +131,13 @@ function popHostContext(fiber: Fiber): void {
pop(hostTransitionProviderCursor, fiber);

// When popping the transition provider, we reset the context value back
// to `null`. We can do this because you're not allowd to nest forms. If
// to `NotPendingTransition`. We can do this because you're not allowd to nest forms. If
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
// we allowed for multiple nested host transition providers, then we'd
// need to reset this to the parent provider's status.
if (isPrimaryRenderer) {
HostTransitionContext._currentValue = null;
HostTransitionContext._currentValue = NotPendingTransition;
} else {
HostTransitionContext._currentValue2 = null;
HostTransitionContext._currentValue2 = NotPendingTransition;
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions packages/react-reconciler/src/ReactFiberNewContext.js
Expand Up @@ -19,7 +19,7 @@ import type {SharedQueue} from './ReactFiberClassUpdateQueue';
import type {TransitionStatus} from './ReactFiberConfig';
import type {Hook} from './ReactFiberHooks';

import {isPrimaryRenderer} from './ReactFiberConfig';
import {isPrimaryRenderer, HostTransitionContext} from './ReactFiberConfig';
import {createCursor, push, pop} from './ReactFiberStack';
import {
ContextProvider,
Expand Down Expand Up @@ -47,10 +47,7 @@ import {
enableAsyncActions,
enableRenderableContext,
} from 'shared/ReactFeatureFlags';
import {
getHostTransitionProvider,
HostTransitionContext,
} from './ReactFiberHostContext';
import {getHostTransitionProvider} from './ReactFiberHostContext';

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

Expand Down
Expand Up @@ -79,6 +79,7 @@ export const startSuspendingCommit = $$$config.startSuspendingCommit;
export const suspendInstance = $$$config.suspendInstance;
export const waitForCommitToBeReady = $$$config.waitForCommitToBeReady;
export const NotPendingTransition = $$$config.NotPendingTransition;
export const HostTransitionContext = $$$config.HostTransitionContext;
export const resetFormInstance = $$$config.resetFormInstance;

// -------------------
Expand Down
11 changes: 11 additions & 0 deletions packages/react-test-renderer/src/ReactFiberConfigTestHost.js
Expand Up @@ -7,7 +7,10 @@
* @flow
*/

import type {ReactContext} from 'shared/ReactTypes';

import isArray from 'shared/isArray';
import {REACT_CONTEXT_TYPE} from 'shared/ReactSymbols';
import {
DefaultEventPriority,
NoEventPriority,
Expand Down Expand Up @@ -349,6 +352,14 @@ export function waitForCommitToBeReady(): null {
}

export const NotPendingTransition: TransitionStatus = null;
export const HostTransitionContext: ReactContext<TransitionStatus> = {
$$typeof: REACT_CONTEXT_TYPE,
Provider: (null: any),
Consumer: (null: any),
_currentValue: NotPendingTransition,
_currentValue2: NotPendingTransition,
_threadCount: 0,
};

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