Skip to content

Commit

Permalink
Ensure useState and useReducer initializer functions are double invok…
Browse files Browse the repository at this point in the history
…ed in StrictMode (#28248)

DiffTrain build for [97fd3e7](97fd3e7)
  • Loading branch information
eps1lon committed Feb 6, 2024
1 parent 47b1b75 commit a52f427
Show file tree
Hide file tree
Showing 19 changed files with 297 additions and 81 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db120f69ec7a0b8c7f38ca7a1ddb1886de92e465
97fd3e7064b162f05b1bac3962ed10c6559c346c
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-19d42c66";
exports.version = "18.3.0-www-classic-f4740bf5";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-www-classic-75f5108a";
exports.version = "18.3.0-www-classic-b75b6a09";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
20 changes: 17 additions & 3 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "18.3.0-www-classic-d2bd5964";
var ReactVersion = "18.3.0-www-classic-6e4380f3";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -9070,6 +9070,12 @@ if (__DEV__) {

if (init !== undefined) {
initialState = init(initialArg);

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -9619,8 +9625,16 @@ if (__DEV__) {
var hook = mountWorkInProgressHook();

if (typeof initialState === "function") {
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
initialState = initialState();
var initialStateInitializer = initialState; // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialState = initialStateInitializer();

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true); // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialStateInitializer();
setIsStrictModeForDevtools(false);
}
}

hook.memoizedState = hook.baseState = initialState;
Expand Down
20 changes: 17 additions & 3 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ if (__DEV__) {
return self;
}

var ReactVersion = "18.3.0-www-modern-3985e4ea";
var ReactVersion = "18.3.0-www-modern-46693fec";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -8820,6 +8820,12 @@ if (__DEV__) {

if (init !== undefined) {
initialState = init(initialArg);

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -9369,8 +9375,16 @@ if (__DEV__) {
var hook = mountWorkInProgressHook();

if (typeof initialState === "function") {
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
initialState = initialState();
var initialStateInitializer = initialState; // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialState = initialStateInitializer();

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true); // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialStateInitializer();
setIsStrictModeForDevtools(false);
}
}

hook.memoizedState = hook.baseState = initialState;
Expand Down
25 changes: 19 additions & 6 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,14 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
initialStateInitializer(),
setIsStrictModeForDevtools(!1));
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -3645,14 +3652,20 @@ var HooksDispatcherOnMount = {
},
useReducer: function (reducer, initialArg, init) {
var hook = mountWorkInProgressHook();
initialArg = void 0 !== init ? init(initialArg) : initialArg;
hook.memoizedState = hook.baseState = initialArg;
if (void 0 !== init) {
var initialState = init(initialArg);
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
init(initialArg),
setIsStrictModeForDevtools(!1));
} else initialState = initialArg;
hook.memoizedState = hook.baseState = initialState;
reducer = {
pending: null,
lanes: 0,
dispatch: null,
lastRenderedReducer: reducer,
lastRenderedState: initialArg
lastRenderedState: initialState
};
hook.queue = reducer;
reducer = reducer.dispatch = dispatchReducerAction.bind(
Expand Down Expand Up @@ -10542,7 +10555,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-classic-776451b9",
version: "18.3.0-www-classic-8f257f8f",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1323 = {
Expand Down Expand Up @@ -10573,7 +10586,7 @@ var internals$jscomp$inline_1323 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-776451b9"
reconcilerVersion: "18.3.0-www-classic-8f257f8f"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1324 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
25 changes: 19 additions & 6 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,14 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
initialStateInitializer(),
setIsStrictModeForDevtools(!1));
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -3452,14 +3459,20 @@ var HooksDispatcherOnMount = {
},
useReducer: function (reducer, initialArg, init) {
var hook = mountWorkInProgressHook();
initialArg = void 0 !== init ? init(initialArg) : initialArg;
hook.memoizedState = hook.baseState = initialArg;
if (void 0 !== init) {
var initialState = init(initialArg);
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
init(initialArg),
setIsStrictModeForDevtools(!1));
} else initialState = initialArg;
hook.memoizedState = hook.baseState = initialState;
reducer = {
pending: null,
lanes: 0,
dispatch: null,
lastRenderedReducer: reducer,
lastRenderedState: initialArg
lastRenderedState: initialState
};
hook.queue = reducer;
reducer = reducer.dispatch = dispatchReducerAction.bind(
Expand Down Expand Up @@ -10208,7 +10221,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-aa622b11",
version: "18.3.0-www-modern-371634b7",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1303 = {
Expand Down Expand Up @@ -10239,7 +10252,7 @@ var internals$jscomp$inline_1303 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-aa622b11"
reconcilerVersion: "18.3.0-www-modern-371634b7"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1304 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
20 changes: 17 additions & 3 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13760,6 +13760,12 @@ if (__DEV__) {

if (init !== undefined) {
initialState = init(initialArg);

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -14342,8 +14348,16 @@ if (__DEV__) {
var hook = mountWorkInProgressHook();

if (typeof initialState === "function") {
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
initialState = initialState();
var initialStateInitializer = initialState; // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialState = initialStateInitializer();

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true); // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialStateInitializer();
setIsStrictModeForDevtools(false);
}
}

hook.memoizedState = hook.baseState = initialState;
Expand Down Expand Up @@ -35736,7 +35750,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-www-classic-399a1fe7";
var ReactVersion = "18.3.0-www-classic-81f24f41";

function createPortal$1(
children,
Expand Down
20 changes: 17 additions & 3 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -13696,6 +13696,12 @@ if (__DEV__) {

if (init !== undefined) {
initialState = init(initialArg);

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -14278,8 +14284,16 @@ if (__DEV__) {
var hook = mountWorkInProgressHook();

if (typeof initialState === "function") {
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
initialState = initialState();
var initialStateInitializer = initialState; // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialState = initialStateInitializer();

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true); // $FlowFixMe[incompatible-use]: Flow doesn't like mixed types

initialStateInitializer();
setIsStrictModeForDevtools(false);
}
}

hook.memoizedState = hook.baseState = initialState;
Expand Down Expand Up @@ -35557,7 +35571,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-www-modern-db8ad56f";
var ReactVersion = "18.3.0-www-modern-13ebed85";

function createPortal$1(
children,
Expand Down
27 changes: 20 additions & 7 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3823,7 +3823,14 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
initialStateInitializer(),
setIsStrictModeForDevtools(!1));
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -4490,14 +4497,20 @@ var HooksDispatcherOnMount = {
},
useReducer: function (reducer, initialArg, init) {
var hook = mountWorkInProgressHook();
initialArg = void 0 !== init ? init(initialArg) : initialArg;
hook.memoizedState = hook.baseState = initialArg;
if (void 0 !== init) {
var initialState = init(initialArg);
shouldDoubleInvokeUserFnsInHooksDEV &&
(setIsStrictModeForDevtools(!0),
init(initialArg),
setIsStrictModeForDevtools(!1));
} else initialState = initialArg;
hook.memoizedState = hook.baseState = initialState;
reducer = {
pending: null,
lanes: 0,
dispatch: null,
lastRenderedReducer: reducer,
lastRenderedState: initialArg
lastRenderedState: initialState
};
hook.queue = reducer;
reducer = reducer.dispatch = dispatchReducerAction.bind(
Expand Down Expand Up @@ -17148,7 +17161,7 @@ Internals.Events = [
var devToolsConfig$jscomp$inline_1823 = {
findFiberByHostInstance: getClosestInstanceFromNode,
bundleType: 0,
version: "18.3.0-www-classic-4cdedb24",
version: "18.3.0-www-classic-e4ba2ec7",
rendererPackageName: "react-dom"
};
var internals$jscomp$inline_2185 = {
Expand Down Expand Up @@ -17178,7 +17191,7 @@ var internals$jscomp$inline_2185 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-classic-4cdedb24"
reconcilerVersion: "18.3.0-www-classic-e4ba2ec7"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2186 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -17528,4 +17541,4 @@ exports.useFormStatus = function () {
return ReactCurrentDispatcher$2.current.useHostTransitionStatus();
throw Error(formatProdErrorMessage(248));
};
exports.version = "18.3.0-www-classic-4cdedb24";
exports.version = "18.3.0-www-classic-e4ba2ec7";
Loading

0 comments on commit a52f427

Please sign in to comment.