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

Ensure updates are applied when diffInCommitPhase is on #26977

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7084,5 +7084,26 @@ background-color: green;
</html>,
);
});

// @gate enableFloat
it('can update title tags', async () => {
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<title data-foo="foo">a title</title>);
});
await waitForAll([]);

expect(getMeaningfulChildren(document.head)).toEqual(
<title data-foo="foo">a title</title>,
);

await act(() => {
root.render(<title data-foo="bar">another title</title>);
});
await waitForAll([]);
expect(getMeaningfulChildren(document.head)).toEqual(
<title data-foo="bar">another title</title>,
);
});
});
});
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ function commitMutationEffectsOnFiber(
const updatePayload: null | UpdatePayload =
(finishedWork.updateQueue: any);
finishedWork.updateQueue = null;
if (updatePayload !== null) {
if (updatePayload !== null || diffInCommitPhase) {
try {
commitUpdate(
finishedWork.stateNode,
Expand Down
49 changes: 31 additions & 18 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,17 +1160,23 @@ function completeWork(
return null;
} else {
// This is a Hoistable Instance
//
// We may have props to update on the Hoistable instance. We use the
// updateHostComponent path becuase it produces the update queue
// we need for Hoistables.
updateHostComponent(
current,
workInProgress,
type,
newProps,
renderLanes,
);
// We may have props to update on the Hoistable instance.
if (diffInCommitPhase && supportsMutation) {
const oldProps = current.memoizedProps;
if (oldProps !== newProps) {
markUpdate(workInProgress);
}
} else {
// We use the updateHostComponent path becuase it produces
// the update queue we need for Hoistables.
updateHostComponent(
current,
workInProgress,
type,
newProps,
renderLanes,
);
}

// This must come at the very end of the complete phase.
bubbleProperties(workInProgress);
Expand All @@ -1192,13 +1198,20 @@ function completeWork(
const rootContainerInstance = getRootHostContainer();
const type = workInProgress.type;
if (current !== null && workInProgress.stateNode != null) {
updateHostComponent(
current,
workInProgress,
type,
newProps,
renderLanes,
);
if (diffInCommitPhase && supportsMutation) {
const oldProps = current.memoizedProps;
if (oldProps !== newProps) {
markUpdate(workInProgress);
}
} else {
updateHostComponent(
current,
workInProgress,
type,
newProps,
renderLanes,
);
}

if (current.ref !== workInProgress.ref) {
markRef(workInProgress);
Expand Down