Skip to content

Commit d629d07

Browse files
committed
[DOM] move flushSync out of the reconciler (#28500)
This PR moves `flushSync` out of the reconciler. there is still an internal implementation that is used when these semantics are needed for React methods such as `unmount` on roots. This new isomorphic `flushSync` is only used in builds that no longer support legacy mode. Additionally all the internal uses of flushSync in the reconciler have been replaced with more direct methods. There is a new `updateContainerSync` method which updates a container but forces it to the Sync lane and flushes passive effects if necessary. This combined with flushSyncWork can be used to replace flushSync for all instances of internal usage. We still maintain the original flushSync implementation as `flushSyncFromReconciler` because it will be used as the flushSync implementation for FB builds. This is because it has special legacy mode handling that the new isomorphic implementation does not need to consider. It will be removed from production OSS builds by closure though DiffTrain build for commit 4c12339.
1 parent bb12450 commit d629d07

File tree

10 files changed

+370
-336
lines changed

10 files changed

+370
-336
lines changed

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

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<7d40122affc60fd6dee01dfb5006f923>>
10+
* @generated SignedSource<<80d7175505ee7b5092250e0e58c47878>>
1111
*/
1212

1313
"use strict";
@@ -121,6 +121,9 @@ if (__DEV__) {
121121

122122
var assign = Object.assign;
123123

124+
var LegacyRoot = 0;
125+
var ConcurrentRoot = 1;
126+
124127
/**
125128
* `ReactInstanceMap` maintains a mapping from a public facing stateful
126129
* instance (key) and the internal representation (value). This allows public
@@ -2867,9 +2870,6 @@ if (__DEV__) {
28672870
}
28682871
}
28692872

2870-
var LegacyRoot = 0;
2871-
var ConcurrentRoot = 1;
2872-
28732873
// We use the existence of the state object as an indicator that the component
28742874
// is hidden.
28752875
var OffscreenVisible =
@@ -22409,11 +22409,11 @@ if (__DEV__) {
2240922409
}
2241022410

2241122411
var PossiblyWeakMap = typeof WeakMap === "function" ? WeakMap : Map;
22412-
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher,
22413-
ReactCurrentCache = ReactSharedInternals.ReactCurrentCache,
22414-
ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner,
22415-
ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig,
22416-
ReactCurrentActQueue = ReactSharedInternals.ReactCurrentActQueue;
22412+
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
22413+
var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
22414+
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
22415+
var ReactCurrentBatchConfig = ReactSharedInternals.ReactCurrentBatchConfig;
22416+
var ReactCurrentActQueue = ReactSharedInternals.ReactCurrentActQueue;
2241722417
var NoContext =
2241822418
/* */
2241922419
0;
@@ -22560,13 +22560,11 @@ if (__DEV__) {
2256022560

2256122561
if (transition !== null) {
2256222562
{
22563-
var batchConfigTransition = ReactCurrentBatchConfig.transition;
22564-
22565-
if (!batchConfigTransition._updatedFibers) {
22566-
batchConfigTransition._updatedFibers = new Set();
22563+
if (!transition._updatedFibers) {
22564+
transition._updatedFibers = new Set();
2256722565
}
2256822566

22569-
batchConfigTransition._updatedFibers.add(fiber);
22567+
transition._updatedFibers.add(fiber);
2257022568
}
2257122569

2257222570
var actionScopeLane = peekEntangledActionLane();
@@ -23265,7 +23263,7 @@ if (__DEV__) {
2326523263
// eslint-disable-next-line no-redeclare
2326623264
// eslint-disable-next-line no-redeclare
2326723265

23268-
function flushSync(fn) {
23266+
function flushSyncFromReconciler(fn) {
2326923267
// In legacy mode, we flush pending passive effects at the beginning of the
2327023268
// next event, not at the end of the previous one.
2327123269
if (
@@ -23305,6 +23303,16 @@ if (__DEV__) {
2330523303
flushSyncWorkOnAllRoots();
2330623304
}
2330723305
}
23306+
} // If called outside of a render or commit will flush all sync work on all roots
23307+
// Returns whether the the call was during a render or not
23308+
23309+
function flushSyncWork() {
23310+
if ((executionContext & (RenderContext | CommitContext)) === NoContext) {
23311+
flushSyncWorkOnAllRoots();
23312+
return false;
23313+
}
23314+
23315+
return true;
2330823316
}
2330923317
// hidden subtree. The stack logic is managed there because that's the only
2331023318
// place that ever modifies it. Which module it lives in doesn't matter for
@@ -25633,13 +25641,12 @@ if (__DEV__) {
2563325641
var staleFamilies = update.staleFamilies,
2563425642
updatedFamilies = update.updatedFamilies;
2563525643
flushPassiveEffects();
25636-
flushSync(function () {
25637-
scheduleFibersWithFamiliesRecursively(
25638-
root.current,
25639-
updatedFamilies,
25640-
staleFamilies
25641-
);
25642-
});
25644+
scheduleFibersWithFamiliesRecursively(
25645+
root.current,
25646+
updatedFamilies,
25647+
staleFamilies
25648+
);
25649+
flushSyncWork();
2564325650
}
2564425651
};
2564525652
var scheduleRoot = function (root, element) {
@@ -25651,10 +25658,8 @@ if (__DEV__) {
2565125658
return;
2565225659
}
2565325660

25654-
flushPassiveEffects();
25655-
flushSync(function () {
25656-
updateContainer(element, root, null, null);
25657-
});
25661+
updateContainerSync(element, root, null, null);
25662+
flushSyncWork();
2565825663
}
2565925664
};
2566025665

@@ -26615,7 +26620,7 @@ if (__DEV__) {
2661526620
return root;
2661626621
}
2661726622

26618-
var ReactVersion = "19.0.0-canary-33793d9f";
26623+
var ReactVersion = "19.0.0-canary-5acb30be";
2661926624

2662026625
/*
2662126626
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol
@@ -26750,13 +26755,52 @@ if (__DEV__) {
2675026755
);
2675126756
}
2675226757
function updateContainer(element, container, parentComponent, callback) {
26758+
var current = container.current;
26759+
var lane = requestUpdateLane(current);
26760+
updateContainerImpl(
26761+
current,
26762+
lane,
26763+
element,
26764+
container,
26765+
parentComponent,
26766+
callback
26767+
);
26768+
return lane;
26769+
}
26770+
function updateContainerSync(
26771+
element,
26772+
container,
26773+
parentComponent,
26774+
callback
26775+
) {
26776+
if (container.tag === LegacyRoot) {
26777+
flushPassiveEffects();
26778+
}
26779+
26780+
var current = container.current;
26781+
updateContainerImpl(
26782+
current,
26783+
SyncLane,
26784+
element,
26785+
container,
26786+
parentComponent,
26787+
callback
26788+
);
26789+
return SyncLane;
26790+
}
26791+
26792+
function updateContainerImpl(
26793+
rootFiber,
26794+
lane,
26795+
element,
26796+
container,
26797+
parentComponent,
26798+
callback
26799+
) {
2675326800
{
2675426801
onScheduleRoot(container, element);
2675526802
}
2675626803

26757-
var current$1 = container.current;
26758-
var lane = requestUpdateLane(current$1);
26759-
2676026804
{
2676126805
markRenderScheduled(lane);
2676226806
}
@@ -26805,14 +26849,12 @@ if (__DEV__) {
2680526849
update.callback = callback;
2680626850
}
2680726851

26808-
var root = enqueueUpdate(current$1, update, lane);
26852+
var root = enqueueUpdate(rootFiber, update, lane);
2680926853

2681026854
if (root !== null) {
26811-
scheduleUpdateOnFiber(root, current$1, lane);
26812-
entangleTransitions(root, current$1, lane);
26855+
scheduleUpdateOnFiber(root, rootFiber, lane);
26856+
entangleTransitions(root, rootFiber, lane);
2681326857
}
26814-
26815-
return lane;
2681626858
}
2681726859
function getPublicRootInstance(container) {
2681826860
var containerFiber = container.current;
@@ -27713,7 +27755,7 @@ if (__DEV__) {
2771327755

2771427756
return getPublicRootInstance(root);
2771527757
},
27716-
unstable_flushSync: flushSync
27758+
unstable_flushSync: flushSyncFromReconciler
2771727759
};
2771827760
Object.defineProperty(entry, "root", {
2771927761
configurable: true,

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

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

1313
"use strict";
@@ -7733,7 +7733,7 @@ function performSyncWorkOnRoot(root, lanes) {
77337733
ensureRootIsScheduled(root);
77347734
return null;
77357735
}
7736-
function flushSync(fn) {
7736+
function flushSyncFromReconciler(fn) {
77377737
null !== rootWithPendingPassiveEffects &&
77387738
0 === rootWithPendingPassiveEffects.tag &&
77397739
0 === (executionContext & 6) &&
@@ -9148,19 +9148,19 @@ function wrapFiber(fiber) {
91489148
fiberToWrapper.set(fiber, wrapper));
91499149
return wrapper;
91509150
}
9151-
var devToolsConfig$jscomp$inline_996 = {
9151+
var devToolsConfig$jscomp$inline_1000 = {
91529152
findFiberByHostInstance: function () {
91539153
throw Error("TestRenderer does not support findFiberByHostInstance()");
91549154
},
91559155
bundleType: 0,
9156-
version: "19.0.0-canary-a6279bb7",
9156+
version: "19.0.0-canary-0c75b31c",
91579157
rendererPackageName: "react-test-renderer"
91589158
};
9159-
var internals$jscomp$inline_1216 = {
9160-
bundleType: devToolsConfig$jscomp$inline_996.bundleType,
9161-
version: devToolsConfig$jscomp$inline_996.version,
9162-
rendererPackageName: devToolsConfig$jscomp$inline_996.rendererPackageName,
9163-
rendererConfig: devToolsConfig$jscomp$inline_996.rendererConfig,
9159+
var internals$jscomp$inline_1222 = {
9160+
bundleType: devToolsConfig$jscomp$inline_1000.bundleType,
9161+
version: devToolsConfig$jscomp$inline_1000.version,
9162+
rendererPackageName: devToolsConfig$jscomp$inline_1000.rendererPackageName,
9163+
rendererConfig: devToolsConfig$jscomp$inline_1000.rendererConfig,
91649164
overrideHookState: null,
91659165
overrideHookStateDeletePath: null,
91669166
overrideHookStateRenamePath: null,
@@ -9177,26 +9177,26 @@ var internals$jscomp$inline_1216 = {
91779177
return null === fiber ? null : fiber.stateNode;
91789178
},
91799179
findFiberByHostInstance:
9180-
devToolsConfig$jscomp$inline_996.findFiberByHostInstance ||
9180+
devToolsConfig$jscomp$inline_1000.findFiberByHostInstance ||
91819181
emptyFindFiberByHostInstance,
91829182
findHostInstancesForRefresh: null,
91839183
scheduleRefresh: null,
91849184
scheduleRoot: null,
91859185
setRefreshHandler: null,
91869186
getCurrentFiber: null,
9187-
reconcilerVersion: "19.0.0-canary-a6279bb7"
9187+
reconcilerVersion: "19.0.0-canary-0c75b31c"
91889188
};
91899189
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
9190-
var hook$jscomp$inline_1217 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
9190+
var hook$jscomp$inline_1223 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
91919191
if (
9192-
!hook$jscomp$inline_1217.isDisabled &&
9193-
hook$jscomp$inline_1217.supportsFiber
9192+
!hook$jscomp$inline_1223.isDisabled &&
9193+
hook$jscomp$inline_1223.supportsFiber
91949194
)
91959195
try {
9196-
(rendererID = hook$jscomp$inline_1217.inject(
9197-
internals$jscomp$inline_1216
9196+
(rendererID = hook$jscomp$inline_1223.inject(
9197+
internals$jscomp$inline_1222
91989198
)),
9199-
(injectedHook = hook$jscomp$inline_1217);
9199+
(injectedHook = hook$jscomp$inline_1223);
92009200
} catch (err) {}
92019201
}
92029202
exports._Scheduler = Scheduler;
@@ -9296,7 +9296,7 @@ exports.create = function (element, options) {
92969296
}
92979297
return JSCompiler_inline_result;
92989298
},
9299-
unstable_flushSync: flushSync
9299+
unstable_flushSync: flushSyncFromReconciler
93009300
};
93019301
Object.defineProperty(element, "root", {
93029302
configurable: !0,

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

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

1313
"use strict";
@@ -8207,7 +8207,7 @@ function performSyncWorkOnRoot(root, lanes) {
82078207
ensureRootIsScheduled(root);
82088208
return null;
82098209
}
8210-
function flushSync(fn) {
8210+
function flushSyncFromReconciler(fn) {
82118211
null !== rootWithPendingPassiveEffects &&
82128212
0 === rootWithPendingPassiveEffects.tag &&
82138213
0 === (executionContext & 6) &&
@@ -9764,12 +9764,12 @@ function wrapFiber(fiber) {
97649764
fiberToWrapper.set(fiber, wrapper));
97659765
return wrapper;
97669766
}
9767-
var devToolsConfig$jscomp$inline_1080 = {
9767+
var devToolsConfig$jscomp$inline_1082 = {
97689768
findFiberByHostInstance: function () {
97699769
throw Error("TestRenderer does not support findFiberByHostInstance()");
97709770
},
97719771
bundleType: 0,
9772-
version: "19.0.0-canary-e4931763",
9772+
version: "19.0.0-canary-091aeabc",
97739773
rendererPackageName: "react-test-renderer"
97749774
};
97759775
(function (internals) {
@@ -9786,10 +9786,10 @@ var devToolsConfig$jscomp$inline_1080 = {
97869786
} catch (err) {}
97879787
return hook.checkDCE ? !0 : !1;
97889788
})({
9789-
bundleType: devToolsConfig$jscomp$inline_1080.bundleType,
9790-
version: devToolsConfig$jscomp$inline_1080.version,
9791-
rendererPackageName: devToolsConfig$jscomp$inline_1080.rendererPackageName,
9792-
rendererConfig: devToolsConfig$jscomp$inline_1080.rendererConfig,
9789+
bundleType: devToolsConfig$jscomp$inline_1082.bundleType,
9790+
version: devToolsConfig$jscomp$inline_1082.version,
9791+
rendererPackageName: devToolsConfig$jscomp$inline_1082.rendererPackageName,
9792+
rendererConfig: devToolsConfig$jscomp$inline_1082.rendererConfig,
97939793
overrideHookState: null,
97949794
overrideHookStateDeletePath: null,
97959795
overrideHookStateRenamePath: null,
@@ -9806,14 +9806,14 @@ var devToolsConfig$jscomp$inline_1080 = {
98069806
return null === fiber ? null : fiber.stateNode;
98079807
},
98089808
findFiberByHostInstance:
9809-
devToolsConfig$jscomp$inline_1080.findFiberByHostInstance ||
9809+
devToolsConfig$jscomp$inline_1082.findFiberByHostInstance ||
98109810
emptyFindFiberByHostInstance,
98119811
findHostInstancesForRefresh: null,
98129812
scheduleRefresh: null,
98139813
scheduleRoot: null,
98149814
setRefreshHandler: null,
98159815
getCurrentFiber: null,
9816-
reconcilerVersion: "19.0.0-canary-e4931763"
9816+
reconcilerVersion: "19.0.0-canary-091aeabc"
98179817
});
98189818
exports._Scheduler = Scheduler;
98199819
exports.act = act;
@@ -9912,7 +9912,7 @@ exports.create = function (element, options) {
99129912
}
99139913
return JSCompiler_inline_result;
99149914
},
9915-
unstable_flushSync: flushSync
9915+
unstable_flushSync: flushSyncFromReconciler
99169916
};
99179917
Object.defineProperty(element, "root", {
99189918
configurable: !0,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8e1462e8c471fbec98aac2b3e1326498d0ff7139
1+
4c12339ce3fa398050d1026c616ea43d43dcaf4a

0 commit comments

Comments
 (0)