Skip to content

Commit

Permalink
Fix: Optimistic update does not get reset (#27453)
Browse files Browse the repository at this point in the history
I found a bug where if an optimistic update causes a component to
rerender, and there are no other state updates during that render, React
bails out without applying the update.

Whenever a hook detects a change, we must mark the component as dirty to
prevent a bailout. We check for changes by comparing the new state to
`hook.memoizedState`. However, when implementing optimistic state
rebasing, I incorrectly reset `hook.memoizedState` to the incoming base
state, even though I only needed to reset `hook.baseState`. This was
just a mistake on my part.

This wasn't caught by the existing tests because usually when the
optimistic state changes, there's also some other state that marks the
component as dirty in the same render.

I fixed the bug and added a regression test.

DiffTrain build for commit 85c2b51.
  • Loading branch information
acdlite committed Oct 3, 2023
1 parent cf37a4c commit e1b35fd
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23997,7 +23997,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-db69f95e4-20231002";
var ReactVersion = "18.3.0-canary-85c2b519b-20231003";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8623,7 +8623,7 @@ var devToolsConfig$jscomp$inline_1030 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-db69f95e4-20231002",
version: "18.3.0-canary-85c2b519b-20231003",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1229 = {
Expand Down Expand Up @@ -8654,7 +8654,7 @@ var internals$jscomp$inline_1229 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-db69f95e4-20231002"
reconcilerVersion: "18.3.0-canary-85c2b519b-20231003"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1230 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9049,7 +9049,7 @@ var devToolsConfig$jscomp$inline_1072 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-db69f95e4-20231002",
version: "18.3.0-canary-85c2b519b-20231003",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1270 = {
Expand Down Expand Up @@ -9080,7 +9080,7 @@ var internals$jscomp$inline_1270 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-db69f95e4-20231002"
reconcilerVersion: "18.3.0-canary-85c2b519b-20231003"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1271 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-canary-db69f95e4-20231002";
var ReactVersion = "18.3.0-canary-85c2b519b-20231003";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-db69f95e4-20231002";
exports.version = "18.3.0-canary-85c2b519b-20231003";
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-db69f95e4-20231002";
exports.version = "18.3.0-canary-85c2b519b-20231003";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db69f95e4876ec3c24117f58d55cbb4f315b9fa7
85c2b519b54269811002d26f4f711809ef68f123

0 comments on commit e1b35fd

Please sign in to comment.