Skip to content

Commit

Permalink
fix[devtools/useTransition]: don't check for dispatch property when d…
Browse files Browse the repository at this point in the history
…etermining if hook is stateful (#27365)

#26740 introduced regression:
React DevTools doesn't record updates for `useTransition` hook. I can
add more details about things on DevTools side, if needed.

The root cause is
https://github.com/facebook/react/blob/491aec5d6113ce5bae7c10966bc38a4a8fc091a8/packages/react-reconciler/src/ReactFiberHooks.js#L2728-L2730

React DevTools expects dispatch to be present for stateful hooks that
can schedule an update -
https://github.com/facebook/react/blob/2eed1328478e8c923fcb4e6abf5efbd9e1233402/packages/react-devtools-shared/src/backend/renderer.js#L1422-L1428

With these changes, we still call dispatch in `startTransition`, but
also patch `queue` object with it, so that React DevTools can recognise
`useTransition` as stateful hook that can schedule update.

I am not sure if this is the right approach to fix this, can we
distinguish if `startTransition` was called from `useTransition` hook or
as a standalone function?

DiffTrain build for commit 56b1447.
  • Loading branch information
hoxyq committed Sep 21, 2023
1 parent e1f7f22 commit b4ab87e
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 @@ -23998,7 +23998,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-canary-68ac6dbcf-20230921";
var ReactVersion = "18.3.0-canary-56b14477e-20230921";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8620,7 +8620,7 @@ var devToolsConfig$jscomp$inline_1028 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-68ac6dbcf-20230921",
version: "18.3.0-canary-56b14477e-20230921",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1227 = {
Expand Down Expand Up @@ -8651,7 +8651,7 @@ var internals$jscomp$inline_1227 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-68ac6dbcf-20230921"
reconcilerVersion: "18.3.0-canary-56b14477e-20230921"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1228 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9046,7 +9046,7 @@ var devToolsConfig$jscomp$inline_1070 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-68ac6dbcf-20230921",
version: "18.3.0-canary-56b14477e-20230921",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1268 = {
Expand Down Expand Up @@ -9077,7 +9077,7 @@ var internals$jscomp$inline_1268 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-68ac6dbcf-20230921"
reconcilerVersion: "18.3.0-canary-56b14477e-20230921"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1269 = __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-68ac6dbcf-20230921";
var ReactVersion = "18.3.0-canary-56b14477e-20230921";

// 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-68ac6dbcf-20230921";
exports.version = "18.3.0-canary-56b14477e-20230921";
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-68ac6dbcf-20230921";
exports.version = "18.3.0-canary-56b14477e-20230921";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68ac6dbcf8d58a67e94e9061395dd96a52d92377
56b14477e902ac076018be2e7bf2ea3092ac9e7d

0 comments on commit b4ab87e

Please sign in to comment.