Skip to content

Commit be884f0

Browse files
committed
Warn if optimistic state is updated outside of a transition (#27454)
### Based on #27453 If optimistic state is updated, and there's no startTransition on the stack, there are two likely scenarios. One possibility is that the optimistic update is triggered by a regular event handler (e.g. `onSubmit`) instead of an action. This is a mistake and we will warn. The other possibility is the optimistic update is inside an async action, but after an `await`. In this case, we can make it "just work" by associating the optimistic update with the pending async action. Technically it's possible that the optimistic update is unrelated to the pending action, but we don't have a way of knowing this for sure because browsers currently do not provide a way to track async scope. (The AsyncContext proposal, if it lands, will solve this in the future.) However, this is no different than the problem of unrelated transitions being grouped together — it's not wrong per se, but it's not ideal. Once AsyncContext starts landing in browsers, we will provide better warnings in development for these cases. DiffTrain build for commit 88d56b8.
1 parent 6f227ff commit be884f0

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<d08221cdf198c30256d8574839ecbf7a>>
10+
* @generated SignedSource<<85d4c20d55cfdfd42f825208f96c046d>>
1111
*/
1212

1313
'use strict';
@@ -8153,14 +8153,14 @@ function startTransition(
81538153
higherEventPriority(previousPriority, ContinuousEventPriority)
81548154
);
81558155
var prevTransition = ReactCurrentBatchConfig$2.transition;
8156+
var currentTransition = {};
81568157

81578158
{
81588159
ReactCurrentBatchConfig$2.transition = null;
81598160
dispatchSetState(fiber, queue, pendingState);
8161+
ReactCurrentBatchConfig$2.transition = currentTransition;
81608162
}
81618163

8162-
var currentTransition = (ReactCurrentBatchConfig$2.transition = {});
8163-
81648164
{
81658165
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
81668166
}
@@ -23997,7 +23997,7 @@ function createFiberRoot(
2399723997
return root;
2399823998
}
2399923999

24000-
var ReactVersion = "18.3.0-canary-bd6891742-20231004";
24000+
var ReactVersion = "18.3.0-canary-88d56b8e8-20231004";
2400124001

2400224002
// Might add PROFILE later.
2400324003

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8623,7 +8623,7 @@ var devToolsConfig$jscomp$inline_1030 = {
86238623
throw Error("TestRenderer does not support findFiberByHostInstance()");
86248624
},
86258625
bundleType: 0,
8626-
version: "18.3.0-canary-bd6891742-20231004",
8626+
version: "18.3.0-canary-88d56b8e8-20231004",
86278627
rendererPackageName: "react-test-renderer"
86288628
};
86298629
var internals$jscomp$inline_1229 = {
@@ -8654,7 +8654,7 @@ var internals$jscomp$inline_1229 = {
86548654
scheduleRoot: null,
86558655
setRefreshHandler: null,
86568656
getCurrentFiber: null,
8657-
reconcilerVersion: "18.3.0-canary-bd6891742-20231004"
8657+
reconcilerVersion: "18.3.0-canary-88d56b8e8-20231004"
86588658
};
86598659
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
86608660
var hook$jscomp$inline_1230 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9049,7 +9049,7 @@ var devToolsConfig$jscomp$inline_1072 = {
90499049
throw Error("TestRenderer does not support findFiberByHostInstance()");
90509050
},
90519051
bundleType: 0,
9052-
version: "18.3.0-canary-bd6891742-20231004",
9052+
version: "18.3.0-canary-88d56b8e8-20231004",
90539053
rendererPackageName: "react-test-renderer"
90549054
};
90559055
var internals$jscomp$inline_1270 = {
@@ -9080,7 +9080,7 @@ var internals$jscomp$inline_1270 = {
90809080
scheduleRoot: null,
90819081
setRefreshHandler: null,
90829082
getCurrentFiber: null,
9083-
reconcilerVersion: "18.3.0-canary-bd6891742-20231004"
9083+
reconcilerVersion: "18.3.0-canary-88d56b8e8-20231004"
90849084
};
90859085
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
90869086
var hook$jscomp$inline_1271 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (
2727
}
2828
"use strict";
2929

30-
var ReactVersion = "18.3.0-canary-bd6891742-20231004";
30+
var ReactVersion = "18.3.0-canary-88d56b8e8-20231004";
3131

3232
// ATTENTION
3333
// When adding new symbols to this file,

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
616616
exports.useTransition = function () {
617617
return ReactCurrentDispatcher.current.useTransition();
618618
};
619-
exports.version = "18.3.0-canary-bd6891742-20231004";
619+
exports.version = "18.3.0-canary-88d56b8e8-20231004";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/cjs/React-profiling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
619619
exports.useTransition = function () {
620620
return ReactCurrentDispatcher.current.useTransition();
621621
};
622-
exports.version = "18.3.0-canary-bd6891742-20231004";
622+
exports.version = "18.3.0-canary-88d56b8e8-20231004";
623623

624624
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
625625
if (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
bd6891742c606a4b8d6ce53760218c6ab3784b38
1+
88d56b8e818d0c48eb6642303169c1fadeb99d59

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<c7798d7e49297e588bffdcccc6aa6cb9>>
10+
* @generated SignedSource<<d547d784dfd2ff8ab9a6adadb432b1cc>>
1111
*/
1212

1313
'use strict';
@@ -12065,14 +12065,14 @@ function startTransition(
1206512065
higherEventPriority(previousPriority, ContinuousEventPriority)
1206612066
);
1206712067
var prevTransition = ReactCurrentBatchConfig$2.transition;
12068+
var currentTransition = {};
1206812069

1206912070
{
1207012071
ReactCurrentBatchConfig$2.transition = null;
1207112072
dispatchSetState(fiber, queue, pendingState);
12073+
ReactCurrentBatchConfig$2.transition = currentTransition;
1207212074
}
1207312075

12074-
var currentTransition = (ReactCurrentBatchConfig$2.transition = {});
12075-
1207612076
{
1207712077
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
1207812078
}
@@ -27063,7 +27063,7 @@ function createFiberRoot(
2706327063
return root;
2706427064
}
2706527065

27066-
var ReactVersion = "18.3.0-canary-4227b2ef";
27066+
var ReactVersion = "18.3.0-canary-112791ea";
2706727067

2706827068
function createPortal$1(
2706927069
children,

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<4d93f2723dd9dce45836c9aa389d421c>>
10+
* @generated SignedSource<<543fb8317c4df4706b2ce72a1d3b1115>>
1111
*/
1212

1313
'use strict';
@@ -12361,14 +12361,14 @@ function startTransition(
1236112361
higherEventPriority(previousPriority, ContinuousEventPriority)
1236212362
);
1236312363
var prevTransition = ReactCurrentBatchConfig$2.transition;
12364+
var currentTransition = {};
1236412365

1236512366
{
1236612367
ReactCurrentBatchConfig$2.transition = null;
1236712368
dispatchSetState(fiber, queue, pendingState);
12369+
ReactCurrentBatchConfig$2.transition = currentTransition;
1236812370
}
1236912371

12370-
var currentTransition = (ReactCurrentBatchConfig$2.transition = {});
12371-
1237212372
{
1237312373
ReactCurrentBatchConfig$2.transition._updatedFibers = new Set();
1237412374
}
@@ -27553,7 +27553,7 @@ function createFiberRoot(
2755327553
return root;
2755427554
}
2755527555

27556-
var ReactVersion = "18.3.0-canary-35bc08a0";
27556+
var ReactVersion = "18.3.0-canary-7f160471";
2755727557

2755827558
function createPortal$1(
2755927559
children,

0 commit comments

Comments
 (0)