Skip to content

Commit

Permalink
Fix suspense replaying forwardRefs with correct secondArg
Browse files Browse the repository at this point in the history
  • Loading branch information
hansottowirtz committed Apr 1, 2023
1 parent e829146 commit d111aa9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,15 +1169,15 @@ export function replayFunctionComponent(
nextProps: any,
Component: any,
renderLanes: Lanes,
secondArg: any
): Fiber | null {
// This function is used to replay a component that previously suspended,
// after its data resolves. It's a simplified version of
// updateFunctionComponent that reuses the hooks from the previous attempt.

let context;
if (!disableLegacyContext) {
if (!disableLegacyContext && secondArg === undefined) {
const unmaskedContext = getUnmaskedContext(workInProgress, Component, true);
context = getMaskedContext(workInProgress, unmaskedContext);
secondArg = getMaskedContext(workInProgress, unmaskedContext);
}

prepareToReadContext(workInProgress, renderLanes);
Expand All @@ -1189,7 +1189,7 @@ export function replayFunctionComponent(
workInProgress,
Component,
nextProps,
context,
secondArg,
);
const hasId = checkDidRenderIdHook();
if (enableSchedulingProfiler) {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,7 @@ function replaySuspendedUnitOfWork(unitOfWork: Fiber): void {
// could maybe use this as an opportunity to say `use` doesn't work with
// `defaultProps` :)
const Component = unitOfWork.tag === FunctionComponent ? unitOfWork.type : unitOfWork.type.render;
const secondArg = unitOfWork.tag === FunctionComponent ? undefined : unitOfWork.ref;
const unresolvedProps = unitOfWork.pendingProps;
const resolvedProps =
unitOfWork.elementType === Component
Expand All @@ -2398,18 +2399,21 @@ function replaySuspendedUnitOfWork(unitOfWork: Fiber): void {
resolvedProps,
Component,
workInProgressRootRenderLanes,
secondArg
);
break;
}
case SimpleMemoComponent: {
const Component = unitOfWork.type;
const nextProps = unitOfWork.pendingProps;
const secondArg = undefined;
next = replayFunctionComponent(
current,
unitOfWork,
nextProps,
Component,
workInProgressRootRenderLanes,
secondArg
);
break;
}
Expand Down

0 comments on commit d111aa9

Please sign in to comment.