Skip to content

Commit

Permalink
Always set baseState
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Sep 19, 2024
1 parent 5700442 commit 9386d33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
9 changes: 3 additions & 6 deletions packages/react-dom/src/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('ReactUpdates', () => {
expect(container.firstChild.textContent).toBe('0');

await act(() => {
// Schedue a transtion to update the state, this means baseQueue is non-empty.
// Schedule a transition to update the state, this means baseQueue is non-empty.
React.startTransition(() => {
_setState(c => c + 1);
});
Expand All @@ -141,12 +141,9 @@ describe('ReactUpdates', () => {
'Layout effect setState',

// Render layout effect update
// BUG!! Renders with base state 0 instead of 1
// 'Render: 0',
// 'setState in render 0 -> 1',

'Render: 1',
// Transition completes

// Render transition completes
'Render: 1',
]);
expect(container.firstChild.textContent).toBe('1');
Expand Down
11 changes: 1 addition & 10 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1620,16 +1620,7 @@ function rerenderReducer<S, I, A>(
}

hook.memoizedState = newState;
// Don't persist the state accumulated from the render phase updates to
// the base state unless the queue is empty.
// TODO: Not sure if this is the desired semantics, but it's what we
// do for gDSFP. I can't remember why.

// TODO: Removing this condition fixes the tests
if (hook.baseQueue === null) {
hook.baseState = newState;
}

hook.baseState = newState;
queue.lastRenderedState = newState;
}
return [newState, dispatch];
Expand Down

0 comments on commit 9386d33

Please sign in to comment.