Skip to content

Commit 16ee5b4

Browse files
committed
Patch devtools before running useMemo function in strict mode (#28249)
This fixes a regression #25583 where we stopped patching before calling useMemo function. Fixes #27989 DiffTrain build for commit db120f6.
1 parent d6ea4c7 commit 16ee5b4

13 files changed

+191
-70
lines changed

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

+115-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3a64021116badb6467add62a13ee5411>>
10+
* @generated SignedSource<<37663b716b538adcc88b05fc968e0638>>
1111
*/
1212

1313
"use strict";
@@ -850,6 +850,103 @@ if (__DEV__) {
850850
var NormalPriority$1 = Scheduler$1.unstable_NormalPriority;
851851
var IdlePriority = Scheduler$1.unstable_IdlePriority; // this doesn't actually exist on the scheduler, but it *does*
852852

853+
// Helpers to patch console.logs to avoid logging during side-effect free
854+
// replaying on render function. This currently only patches the object
855+
// lazily which won't cover if the log function was extracted eagerly.
856+
// We could also eagerly patch the method.
857+
var disabledDepth = 0;
858+
var prevLog;
859+
var prevInfo;
860+
var prevWarn;
861+
var prevError;
862+
var prevGroup;
863+
var prevGroupCollapsed;
864+
var prevGroupEnd;
865+
866+
function disabledLog() {}
867+
868+
disabledLog.__reactDisabledLog = true;
869+
function disableLogs() {
870+
{
871+
if (disabledDepth === 0) {
872+
/* eslint-disable react-internal/no-production-logging */
873+
prevLog = console.log;
874+
prevInfo = console.info;
875+
prevWarn = console.warn;
876+
prevError = console.error;
877+
prevGroup = console.group;
878+
prevGroupCollapsed = console.groupCollapsed;
879+
prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
880+
881+
var props = {
882+
configurable: true,
883+
enumerable: true,
884+
value: disabledLog,
885+
writable: true
886+
}; // $FlowFixMe[cannot-write] Flow thinks console is immutable.
887+
888+
Object.defineProperties(console, {
889+
info: props,
890+
log: props,
891+
warn: props,
892+
error: props,
893+
group: props,
894+
groupCollapsed: props,
895+
groupEnd: props
896+
});
897+
/* eslint-enable react-internal/no-production-logging */
898+
}
899+
900+
disabledDepth++;
901+
}
902+
}
903+
function reenableLogs() {
904+
{
905+
disabledDepth--;
906+
907+
if (disabledDepth === 0) {
908+
/* eslint-disable react-internal/no-production-logging */
909+
var props = {
910+
configurable: true,
911+
enumerable: true,
912+
writable: true
913+
}; // $FlowFixMe[cannot-write] Flow thinks console is immutable.
914+
915+
Object.defineProperties(console, {
916+
log: assign({}, props, {
917+
value: prevLog
918+
}),
919+
info: assign({}, props, {
920+
value: prevInfo
921+
}),
922+
warn: assign({}, props, {
923+
value: prevWarn
924+
}),
925+
error: assign({}, props, {
926+
value: prevError
927+
}),
928+
group: assign({}, props, {
929+
value: prevGroup
930+
}),
931+
groupCollapsed: assign({}, props, {
932+
value: prevGroupCollapsed
933+
}),
934+
groupEnd: assign({}, props, {
935+
value: prevGroupEnd
936+
})
937+
});
938+
/* eslint-enable react-internal/no-production-logging */
939+
}
940+
941+
if (disabledDepth < 0) {
942+
error(
943+
"disabledDepth fell below zero. " +
944+
"This is a bug in React. Please file an issue."
945+
);
946+
}
947+
}
948+
}
949+
853950
var rendererID = null;
854951
var injectedHook = null;
855952
var hasLoggedError = false;
@@ -1008,6 +1105,15 @@ if (__DEV__) {
10081105
}
10091106
}
10101107
}
1108+
function setIsStrictModeForDevtools(newIsStrictMode) {
1109+
{
1110+
if (newIsStrictMode) {
1111+
disableLogs();
1112+
} else {
1113+
reenableLogs();
1114+
}
1115+
}
1116+
} // Profiler API hooks
10111117

10121118
function injectProfilingHooks(profilingHooks) {}
10131119

@@ -8759,12 +8865,14 @@ if (__DEV__) {
87598865
function mountMemo(nextCreate, deps) {
87608866
var hook = mountWorkInProgressHook();
87618867
var nextDeps = deps === undefined ? null : deps;
8868+
var nextValue = nextCreate();
87628869

87638870
if (shouldDoubleInvokeUserFnsInHooksDEV) {
8871+
setIsStrictModeForDevtools(true);
87648872
nextCreate();
8873+
setIsStrictModeForDevtools(false);
87658874
}
87668875

8767-
var nextValue = nextCreate();
87688876
hook.memoizedState = [nextValue, nextDeps];
87698877
return nextValue;
87708878
}
@@ -8782,11 +8890,14 @@ if (__DEV__) {
87828890
}
87838891
}
87848892

8893+
var nextValue = nextCreate();
8894+
87858895
if (shouldDoubleInvokeUserFnsInHooksDEV) {
8896+
setIsStrictModeForDevtools(true);
87868897
nextCreate();
8898+
setIsStrictModeForDevtools(false);
87878899
}
87888900

8789-
var nextValue = nextCreate();
87908901
hook.memoizedState = [nextValue, nextDeps];
87918902
return nextValue;
87928903
}
@@ -25600,7 +25711,7 @@ if (__DEV__) {
2560025711
return root;
2560125712
}
2560225713

25603-
var ReactVersion = "18.3.0-canary-12d56fca3-20240206";
25714+
var ReactVersion = "18.3.0-canary-db120f69e-20240206";
2560425715

2560525716
// Might add PROFILE later.
2560625717

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<44ff806ec3569d53375d403127ca45fb>>
10+
* @generated SignedSource<<d9636c72045c34ee5d5bc57f2f84aa96>>
1111
*/
1212

1313
"use strict";
@@ -2889,10 +2889,10 @@ function updateMemo(nextCreate, deps) {
28892889
var prevState = hook.memoizedState;
28902890
if (null !== deps && areHookInputsEqual(deps, prevState[1]))
28912891
return prevState[0];
2892+
prevState = nextCreate();
28922893
shouldDoubleInvokeUserFnsInHooksDEV && nextCreate();
2893-
nextCreate = nextCreate();
2894-
hook.memoizedState = [nextCreate, deps];
2895-
return nextCreate;
2894+
hook.memoizedState = [prevState, deps];
2895+
return prevState;
28962896
}
28972897
function mountDeferredValueImpl(hook, value, initialValue) {
28982898
if (void 0 === initialValue || 0 !== (renderLanes & 1073741824))
@@ -3135,10 +3135,10 @@ var HooksDispatcherOnMount = {
31353135
useMemo: function (nextCreate, deps) {
31363136
var hook = mountWorkInProgressHook();
31373137
deps = void 0 === deps ? null : deps;
3138+
var nextValue = nextCreate();
31383139
shouldDoubleInvokeUserFnsInHooksDEV && nextCreate();
3139-
nextCreate = nextCreate();
3140-
hook.memoizedState = [nextCreate, deps];
3141-
return nextCreate;
3140+
hook.memoizedState = [nextValue, deps];
3141+
return nextValue;
31423142
},
31433143
useReducer: function (reducer, initialArg, init) {
31443144
var hook = mountWorkInProgressHook();
@@ -9150,7 +9150,7 @@ var devToolsConfig$jscomp$inline_1012 = {
91509150
throw Error("TestRenderer does not support findFiberByHostInstance()");
91519151
},
91529152
bundleType: 0,
9153-
version: "18.3.0-canary-12d56fca3-20240206",
9153+
version: "18.3.0-canary-db120f69e-20240206",
91549154
rendererPackageName: "react-test-renderer"
91559155
};
91569156
var internals$jscomp$inline_1190 = {
@@ -9181,7 +9181,7 @@ var internals$jscomp$inline_1190 = {
91819181
scheduleRoot: null,
91829182
setRefreshHandler: null,
91839183
getCurrentFiber: null,
9184-
reconcilerVersion: "18.3.0-canary-12d56fca3-20240206"
9184+
reconcilerVersion: "18.3.0-canary-db120f69e-20240206"
91859185
};
91869186
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
91879187
var hook$jscomp$inline_1191 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<cbdd4098615e3e8ca00b094256cf3374>>
10+
* @generated SignedSource<<b435a772ad86c95cee4ea13ae18ef64a>>
1111
*/
1212

1313
"use strict";
@@ -2909,10 +2909,10 @@ function updateMemo(nextCreate, deps) {
29092909
var prevState = hook.memoizedState;
29102910
if (null !== deps && areHookInputsEqual(deps, prevState[1]))
29112911
return prevState[0];
2912+
prevState = nextCreate();
29122913
shouldDoubleInvokeUserFnsInHooksDEV && nextCreate();
2913-
nextCreate = nextCreate();
2914-
hook.memoizedState = [nextCreate, deps];
2915-
return nextCreate;
2914+
hook.memoizedState = [prevState, deps];
2915+
return prevState;
29162916
}
29172917
function mountDeferredValueImpl(hook, value, initialValue) {
29182918
if (void 0 === initialValue || 0 !== (renderLanes & 1073741824))
@@ -3155,10 +3155,10 @@ var HooksDispatcherOnMount = {
31553155
useMemo: function (nextCreate, deps) {
31563156
var hook = mountWorkInProgressHook();
31573157
deps = void 0 === deps ? null : deps;
3158+
var nextValue = nextCreate();
31583159
shouldDoubleInvokeUserFnsInHooksDEV && nextCreate();
3159-
nextCreate = nextCreate();
3160-
hook.memoizedState = [nextCreate, deps];
3161-
return nextCreate;
3160+
hook.memoizedState = [nextValue, deps];
3161+
return nextValue;
31623162
},
31633163
useReducer: function (reducer, initialArg, init) {
31643164
var hook = mountWorkInProgressHook();
@@ -9578,7 +9578,7 @@ var devToolsConfig$jscomp$inline_1054 = {
95789578
throw Error("TestRenderer does not support findFiberByHostInstance()");
95799579
},
95809580
bundleType: 0,
9581-
version: "18.3.0-canary-12d56fca3-20240206",
9581+
version: "18.3.0-canary-db120f69e-20240206",
95829582
rendererPackageName: "react-test-renderer"
95839583
};
95849584
var internals$jscomp$inline_1231 = {
@@ -9609,7 +9609,7 @@ var internals$jscomp$inline_1231 = {
96099609
scheduleRoot: null,
96109610
setRefreshHandler: null,
96119611
getCurrentFiber: null,
9612-
reconcilerVersion: "18.3.0-canary-12d56fca3-20240206"
9612+
reconcilerVersion: "18.3.0-canary-db120f69e-20240206"
96139613
};
96149614
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
96159615
var hook$jscomp$inline_1232 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (__DEV__) {
2424
) {
2525
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2626
}
27-
var ReactVersion = "18.3.0-canary-12d56fca3-20240206";
27+
var ReactVersion = "18.3.0-canary-db120f69e-20240206";
2828

2929
// ATTENTION
3030
// When adding new symbols to this file,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,4 @@ exports.useSyncExternalStore = function (
543543
exports.useTransition = function () {
544544
return ReactCurrentDispatcher.current.useTransition();
545545
};
546-
exports.version = "18.3.0-canary-12d56fca3-20240206";
546+
exports.version = "18.3.0-canary-db120f69e-20240206";

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ exports.useSyncExternalStore = function (
539539
exports.useTransition = function () {
540540
return ReactCurrentDispatcher.current.useTransition();
541541
};
542-
exports.version = "18.3.0-canary-12d56fca3-20240206";
542+
exports.version = "18.3.0-canary-db120f69e-20240206";
543543
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
544544
"function" ===
545545
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12d56fca3da06328ac61d86976afa728b97b49d6
1+
db120f69ec7a0b8c7f38ca7a1ddb1886de92e465

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<55b0b6588c8d91990b5450183181983a>>
10+
* @generated SignedSource<<3a837b194f39df56fc660016dea4e217>>
1111
*/
1212

1313
"use strict";
@@ -12226,12 +12226,14 @@ to return true:wantsResponderID| |
1222612226
function mountMemo(nextCreate, deps) {
1222712227
var hook = mountWorkInProgressHook();
1222812228
var nextDeps = deps === undefined ? null : deps;
12229+
var nextValue = nextCreate();
1222912230

1223012231
if (shouldDoubleInvokeUserFnsInHooksDEV) {
12232+
setIsStrictModeForDevtools(true);
1223112233
nextCreate();
12234+
setIsStrictModeForDevtools(false);
1223212235
}
1223312236

12234-
var nextValue = nextCreate();
1223512237
hook.memoizedState = [nextValue, nextDeps];
1223612238
return nextValue;
1223712239
}
@@ -12249,11 +12251,14 @@ to return true:wantsResponderID| |
1224912251
}
1225012252
}
1225112253

12254+
var nextValue = nextCreate();
12255+
1225212256
if (shouldDoubleInvokeUserFnsInHooksDEV) {
12257+
setIsStrictModeForDevtools(true);
1225312258
nextCreate();
12259+
setIsStrictModeForDevtools(false);
1225412260
}
1225512261

12256-
var nextValue = nextCreate();
1225712262
hook.memoizedState = [nextValue, nextDeps];
1225812263
return nextValue;
1225912264
}
@@ -27837,7 +27842,7 @@ to return true:wantsResponderID| |
2783727842
return root;
2783827843
}
2783927844

27840-
var ReactVersion = "18.3.0-canary-c019ca0a";
27845+
var ReactVersion = "18.3.0-canary-bd49981d";
2784127846

2784227847
function createPortal$1(
2784327848
children,

0 commit comments

Comments
 (0)