Skip to content

Commit 79f01b2

Browse files
committed
prepareForCommit returns info object to be passed resetAfterCommit
The DOM renderer assumes that resetAfterCommit is called after prepareForCommit without any nested commits in between. That may not be the case now that syncUpdates forces a nested update. To address, this changes the type of prepareForCommit to return a value which is later passed to resetAfterCommit.
1 parent ce8c978 commit 79f01b2

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

scripts/fiber/tests-passing.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalScheduling-test.js
12071207
* can opt-in to deferred/animation scheduling inside componentDidMount/Update
12081208
* performs Task work even after time runs out
12091209
* does not perform animation work after time runs out
1210+
* can force synchronous updates with syncUpdates, even inside batchedUpdates
12101211

12111212
src/renderers/shared/fiber/__tests__/ReactIncrementalSideEffects-test.js
12121213
* can update child nodes of a host instance
@@ -1576,6 +1577,7 @@ src/renderers/shared/shared/__tests__/ReactUpdates-test.js
15761577
* unstable_batchedUpdates should return value from a callback
15771578
* unmounts and remounts a root in the same batch
15781579
* handles reentrant mounting in synchronous mode
1580+
* mounts and unmounts are sync even in a batch
15791581

15801582
src/renderers/shared/shared/__tests__/refs-destruction-test.js
15811583
* should remove refs when destroying the parent

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ type HostContextDev = {
6767
};
6868
type HostContextProd = string;
6969
type HostContext = HostContextDev | HostContextProd;
70-
71-
let eventsEnabled : ?boolean = null;
72-
let selectionInformation : ?mixed = null;
70+
type CommitInfo = {
71+
eventsEnabled: boolean,
72+
selectionInformation: mixed,
73+
};
7374

7475
var ELEMENT_NODE_TYPE = 1;
7576
var DOC_NODE_TYPE = 9;
@@ -137,17 +138,18 @@ var DOMRenderer = ReactFiberReconciler({
137138
return getChildNamespace(parentNamespace, type);
138139
},
139140

140-
prepareForCommit() : void {
141-
eventsEnabled = ReactBrowserEventEmitter.isEnabled();
141+
prepareForCommit() : CommitInfo {
142+
const eventsEnabled = ReactBrowserEventEmitter.isEnabled();
142143
ReactBrowserEventEmitter.setEnabled(false);
143-
selectionInformation = ReactInputSelection.getSelectionInformation();
144+
return {
145+
eventsEnabled,
146+
selectionInformation: ReactInputSelection.getSelectionInformation(),
147+
};
144148
},
145149

146-
resetAfterCommit() : void {
147-
ReactInputSelection.restoreSelection(selectionInformation);
148-
selectionInformation = null;
149-
ReactBrowserEventEmitter.setEnabled(eventsEnabled);
150-
eventsEnabled = null;
150+
resetAfterCommit(commitInfo : CommitInfo) : void {
151+
ReactInputSelection.restoreSelection(commitInfo.selectionInformation);
152+
ReactBrowserEventEmitter.setEnabled(commitInfo.eventsEnabled);
151153
},
152154

153155
createInstance(

src/renderers/shared/fiber/ReactFiberBeginWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ if (__DEV__) {
6666
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
6767
}
6868

69-
module.exports = function<T, P, I, TI, C, CX>(
70-
config : HostConfig<T, P, I, TI, C, CX>,
69+
module.exports = function<T, P, I, TI, C, CX, CI>(
70+
config : HostConfig<T, P, I, TI, C, CX, CI>,
7171
hostContext : HostContext<C, CX>,
7272
scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void,
7373
getPriorityContext : () => PriorityLevel,

src/renderers/shared/fiber/ReactFiberCommitWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ var {
3333
ContentReset,
3434
} = require('ReactTypeOfSideEffect');
3535

36-
module.exports = function<T, P, I, TI, C, CX>(
37-
config : HostConfig<T, P, I, TI, C, CX>,
36+
module.exports = function<T, P, I, TI, C, CX, CI>(
37+
config : HostConfig<T, P, I, TI, C, CX, CI>,
3838
hostContext : HostContext<C, CX>,
3939
captureError : (failedFiber : Fiber, error: Error) => ?Fiber
4040
) {

src/renderers/shared/fiber/ReactFiberCompleteWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ if (__DEV__) {
4646
var ReactDebugCurrentFiber = require('ReactDebugCurrentFiber');
4747
}
4848

49-
module.exports = function<T, P, I, TI, C, CX>(
50-
config : HostConfig<T, P, I, TI, C, CX>,
49+
module.exports = function<T, P, I, TI, C, CX, CI>(
50+
config : HostConfig<T, P, I, TI, C, CX, CI>,
5151
hostContext : HostContext<C, CX>,
5252
) {
5353
const {

src/renderers/shared/fiber/ReactFiberHostContext.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export type HostContext<C, CX> = {
3434
resetHostContainer() : void,
3535
};
3636

37-
module.exports = function<T, P, I, TI, C, CX>(
38-
config : HostConfig<T, P, I, TI, C, CX>
37+
module.exports = function<T, P, I, TI, C, CX, CI>(
38+
config : HostConfig<T, P, I, TI, C, CX, CI>
3939
) : HostContext<C, CX> {
4040
const {
4141
getChildHostContext,

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type Deadline = {
4343

4444
type OpaqueNode = Fiber;
4545

46-
export type HostConfig<T, P, I, TI, C, CX> = {
46+
export type HostConfig<T, P, I, TI, C, CX, CI> = {
4747

4848
getRootHostContext(rootContainerInstance : C) : CX,
4949
getChildHostContext(parentHostContext : CX, type : T) : CX,
@@ -69,8 +69,8 @@ export type HostConfig<T, P, I, TI, C, CX> = {
6969
scheduleAnimationCallback(callback : () => void) : void,
7070
scheduleDeferredCallback(callback : (deadline : Deadline) => void) : void,
7171

72-
prepareForCommit() : void,
73-
resetAfterCommit() : void,
72+
prepareForCommit() : CI,
73+
resetAfterCommit(commitInfo : CI) : void,
7474

7575
useSyncScheduling ?: boolean,
7676
};
@@ -100,7 +100,7 @@ getContextForSubtree._injectFiber(function(fiber : Fiber) {
100100
parentContext;
101101
});
102102

103-
module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C, CX>) : Reconciler<C, I, TI> {
103+
module.exports = function<T, P, I, TI, C, CX, CI>(config : HostConfig<T, P, I, TI, C, CX, CI>) : Reconciler<C, I, TI> {
104104

105105
var {
106106
scheduleUpdate,

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ if (__DEV__) {
7474

7575
var timeHeuristicForUnitOfWork = 1;
7676

77-
module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C, CX>) {
77+
module.exports = function<T, P, I, TI, C, CX, CI>(config : HostConfig<T, P, I, TI, C, CX, CI>) {
7878
const hostContext = ReactFiberHostContext(config);
7979
const { popHostContainer, popHostContext, resetHostContainer } = hostContext;
8080
const { beginWork, beginFailedWork } = ReactFiberBeginWork(
@@ -348,7 +348,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
348348
firstEffect = finishedWork.firstEffect;
349349
}
350350

351-
prepareForCommit();
351+
const commitInfo = prepareForCommit();
352352

353353
// Commit all the side-effects within a tree. We'll do this in two passes.
354354
// The first pass performs all the host insertions, updates, deletions and
@@ -369,7 +369,7 @@ module.exports = function<T, P, I, TI, C, CX>(config : HostConfig<T, P, I, TI, C
369369
}
370370
}
371371

372-
resetAfterCommit();
372+
resetAfterCommit(commitInfo);
373373

374374
// In the second pass we'll perform all life-cycles and ref callbacks.
375375
// Life-cycles happen as a separate pass so that all placements, updates,

0 commit comments

Comments
 (0)