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 commit 97fd3e7.
  • Loading branch information
eps1lon committed Feb 6, 2024
1 parent 7d75944 commit 425dc7d
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<37663b716b538adcc88b05fc968e0638>>
* @generated SignedSource<<9f26c06d9827c84f3688ced85cc3f175>>
*/

"use strict";
Expand Down Expand Up @@ -7717,6 +7717,12 @@ if (__DEV__) {

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

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -8266,8 +8272,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 @@ -25711,7 +25725,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "18.3.0-canary-08d6cef46-20240206";
var ReactVersion = "18.3.0-canary-97fd3e706-20240206";

// Might add PROFILE later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<d9636c72045c34ee5d5bc57f2f84aa96>>
* @generated SignedSource<<379c4788c6c39f07c9097d9bf684b088>>
*/

"use strict";
Expand Down Expand Up @@ -2695,7 +2695,11 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV && initialStateInitializer();
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -3142,14 +3146,17 @@ 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 && init(initialArg);
} 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 @@ -9150,7 +9157,7 @@ var devToolsConfig$jscomp$inline_1012 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-08d6cef46-20240206",
version: "18.3.0-canary-97fd3e706-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1190 = {
Expand Down Expand Up @@ -9181,7 +9188,7 @@ var internals$jscomp$inline_1190 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-08d6cef46-20240206"
reconcilerVersion: "18.3.0-canary-97fd3e706-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1191 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<b435a772ad86c95cee4ea13ae18ef64a>>
* @generated SignedSource<<4d7854cad1374a2d78104bc407724b7c>>
*/

"use strict";
Expand Down Expand Up @@ -2715,7 +2715,11 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV && initialStateInitializer();
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -3162,14 +3166,17 @@ 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 && init(initialArg);
} 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 @@ -9578,7 +9585,7 @@ var devToolsConfig$jscomp$inline_1054 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-08d6cef46-20240206",
version: "18.3.0-canary-97fd3e706-20240206",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1231 = {
Expand Down Expand Up @@ -9609,7 +9616,7 @@ var internals$jscomp$inline_1231 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-08d6cef46-20240206"
reconcilerVersion: "18.3.0-canary-97fd3e706-20240206"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (__DEV__) {
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = "18.3.0-canary-08d6cef46-20240206";
var ReactVersion = "18.3.0-canary-97fd3e706-20240206";

// ATTENTION
// When adding new symbols to this file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-08d6cef46-20240206";
exports.version = "18.3.0-canary-97fd3e706-20240206";
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-08d6cef46-20240206";
exports.version = "18.3.0-canary-97fd3e706-20240206";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
08d6cef46ab7310b6e8f4330e2fd23586a026a9c
97fd3e7064b162f05b1bac3962ed10c6559c346c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<3a837b194f39df56fc660016dea4e217>>
* @generated SignedSource<<c14b1fb9b87871f4d90100521fdaced4>>
*/

"use strict";
Expand Down Expand Up @@ -11367,6 +11367,12 @@ to return true:wantsResponderID| |

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

if (shouldDoubleInvokeUserFnsInHooksDEV) {
setIsStrictModeForDevtools(true);
init(initialArg);
setIsStrictModeForDevtools(false);
}
} else {
initialState = initialArg;
}
Expand Down Expand Up @@ -11862,8 +11868,16 @@ to return true:wantsResponderID| |
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 @@ -27842,7 +27856,7 @@ to return true:wantsResponderID| |
return root;
}

var ReactVersion = "18.3.0-canary-bd49981d";
var ReactVersion = "18.3.0-canary-ff7bedcd";

function createPortal$1(
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<220e08ac3bea6618aef64c22997dbb19>>
* @generated SignedSource<<323d72c9accf6b4e282ab64f1454bb9c>>
*/

"use strict";
Expand Down Expand Up @@ -3951,7 +3951,11 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV && initialStateInitializer();
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -4240,14 +4244,17 @@ 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 && init(initialArg);
} 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 @@ -9551,7 +9558,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1055 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-canary-89078c3f",
version: "18.3.0-canary-e34746ba",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -9594,7 +9601,7 @@ var internals$jscomp$inline_1277 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-89078c3f"
reconcilerVersion: "18.3.0-canary-e34746ba"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1278 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<ea05f6ff9354df63b851a9e6de2119eb>>
* @generated SignedSource<<b774b4f72e37b4cccbba7d6f16797461>>
*/

"use strict";
Expand Down Expand Up @@ -4076,7 +4076,11 @@ function forceStoreRerender(fiber) {
}
function mountStateImpl(initialState) {
var hook = mountWorkInProgressHook();
"function" === typeof initialState && (initialState = initialState());
if ("function" === typeof initialState) {
var initialStateInitializer = initialState;
initialState = initialStateInitializer();
shouldDoubleInvokeUserFnsInHooksDEV && initialStateInitializer();
}
hook.memoizedState = hook.baseState = initialState;
hook.queue = {
pending: null,
Expand Down Expand Up @@ -4367,14 +4371,17 @@ 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 && init(initialArg);
} 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 @@ -10254,7 +10261,7 @@ var roots = new Map(),
devToolsConfig$jscomp$inline_1133 = {
findFiberByHostInstance: getInstanceFromNode,
bundleType: 0,
version: "18.3.0-canary-456a9bde",
version: "18.3.0-canary-56f3cd40",
rendererPackageName: "react-native-renderer",
rendererConfig: {
getInspectorDataForInstance: getInspectorDataForInstance,
Expand Down Expand Up @@ -10310,7 +10317,7 @@ var roots = new Map(),
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-456a9bde"
reconcilerVersion: "18.3.0-canary-56f3cd40"
});
exports.createPortal = function (children, containerTag) {
return createPortal$1(
Expand Down
Loading

0 comments on commit 425dc7d

Please sign in to comment.