Skip to content

Commit 15fb8c3

Browse files
author
Brian Vaughn
authored
createRoot API is no longer strict by default (#21417)
1 parent aea7c2a commit 15fb8c3

24 files changed

+148
-370
lines changed

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,10 @@ describe('ReactTestUtils.act()', () => {
9797
});
9898

9999
// @gate experimental
100-
it('warns in concurrent mode', () => {
101-
expect(() => {
102-
const root = ReactDOM.unstable_createRoot(
103-
document.createElement('div'),
104-
);
105-
root.render(<App />);
106-
Scheduler.unstable_flushAll();
107-
}).toErrorDev([
108-
'An update to App ran an effect, but was not wrapped in act(...)',
109-
]);
100+
it('does not warn in concurrent mode', () => {
101+
const root = ReactDOM.unstable_createRoot(document.createElement('div'));
102+
root.render(<App />);
103+
Scheduler.unstable_flushAll();
110104
});
111105
});
112106
});

packages/react-dom/src/client/ReactDOMRoot.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export type RootOptions = {
2727
mutableSources?: Array<MutableSource<any>>,
2828
...
2929
},
30-
unstable_strictModeLevel?: number,
3130
unstable_concurrentUpdatesByDefault?: boolean,
3231
...
3332
};
@@ -123,10 +122,6 @@ function createRootImpl(
123122
options.hydrationOptions != null &&
124123
options.hydrationOptions.mutableSources) ||
125124
null;
126-
const strictModeLevelOverride =
127-
options != null && options.unstable_strictModeLevel != null
128-
? options.unstable_strictModeLevel
129-
: null;
130125

131126
let concurrentUpdatesByDefaultOverride = null;
132127
if (allowConcurrentByDefault) {
@@ -141,7 +136,6 @@ function createRootImpl(
141136
tag,
142137
hydrate,
143138
hydrationCallbacks,
144-
strictModeLevelOverride,
145139
concurrentUpdatesByDefaultOverride,
146140
);
147141
markContainerAsRoot(root.current, container);

packages/react-native-renderer/src/ReactFabric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function render(
207207
if (!root) {
208208
// TODO (bvaughn): If we decide to keep the wrapper component,
209209
// We could create a wrapper for containerTag as well to reduce special casing.
210-
root = createContainer(containerTag, LegacyRoot, false, null, null, null);
210+
root = createContainer(containerTag, LegacyRoot, false, null, null);
211211
roots.set(containerTag, root);
212212
}
213213
updateContainer(element, root, null, callback);

packages/react-native-renderer/src/ReactNativeRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function render(
203203
if (!root) {
204204
// TODO (bvaughn): If we decide to keep the wrapper component,
205205
// We could create a wrapper for containerTag as well to reduce special casing.
206-
root = createContainer(containerTag, LegacyRoot, false, null, null, null);
206+
root = createContainer(containerTag, LegacyRoot, false, null, null);
207207
roots.set(containerTag, root);
208208
}
209209
updateContainer(element, root, null, callback);

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
722722
if (!root) {
723723
const container = {rootID: rootID, pendingChildren: [], children: []};
724724
rootContainers.set(rootID, container);
725-
root = NoopRenderer.createContainer(container, tag, false, null, null);
725+
root = NoopRenderer.createContainer(container, tag, false, null);
726726
roots.set(rootID, root);
727727
}
728728
return root.current.stateNode.containerInfo;
@@ -740,7 +740,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
740740
ConcurrentRoot,
741741
false,
742742
null,
743-
null,
744743
);
745744
return {
746745
_Scheduler: Scheduler,
@@ -767,7 +766,6 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
767766
LegacyRoot,
768767
false,
769768
null,
770-
null,
771769
);
772770
return {
773771
_Scheduler: Scheduler,

packages/react-reconciler/src/ReactFiber.new.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,13 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
422422

423423
export function createHostRootFiber(
424424
tag: RootTag,
425-
strictModeLevelOverride: null | number,
426425
concurrentUpdatesByDefaultOverride: null | boolean,
427426
): Fiber {
428427
let mode;
429428
if (tag === ConcurrentRoot) {
430429
mode = ConcurrentMode;
431-
if (strictModeLevelOverride !== null) {
432-
if (strictModeLevelOverride >= 1) {
433-
mode |= StrictLegacyMode;
434-
}
435-
if (enableStrictEffects) {
436-
if (strictModeLevelOverride >= 2) {
437-
mode |= StrictEffectsMode;
438-
}
439-
}
440-
} else {
441-
if (enableStrictEffects && createRootStrictEffectsByDefault) {
442-
mode |= StrictLegacyMode | StrictEffectsMode;
443-
} else {
444-
mode |= StrictLegacyMode;
445-
}
430+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
431+
mode |= StrictLegacyMode | StrictEffectsMode;
446432
}
447433
if (
448434
// We only use this flag for our repo tests to check both behaviors.

packages/react-reconciler/src/ReactFiber.old.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,27 +422,13 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) {
422422

423423
export function createHostRootFiber(
424424
tag: RootTag,
425-
strictModeLevelOverride: null | number,
426425
concurrentUpdatesByDefaultOverride: null | boolean,
427426
): Fiber {
428427
let mode;
429428
if (tag === ConcurrentRoot) {
430429
mode = ConcurrentMode;
431-
if (strictModeLevelOverride !== null) {
432-
if (strictModeLevelOverride >= 1) {
433-
mode |= StrictLegacyMode;
434-
}
435-
if (enableStrictEffects) {
436-
if (strictModeLevelOverride >= 2) {
437-
mode |= StrictEffectsMode;
438-
}
439-
}
440-
} else {
441-
if (enableStrictEffects && createRootStrictEffectsByDefault) {
442-
mode |= StrictLegacyMode | StrictEffectsMode;
443-
} else {
444-
mode |= StrictLegacyMode;
445-
}
430+
if (enableStrictEffects && createRootStrictEffectsByDefault) {
431+
mode |= StrictLegacyMode | StrictEffectsMode;
446432
}
447433
if (
448434
// We only use this flag for our repo tests to check both behaviors.

packages/react-reconciler/src/ReactFiberReconciler.new.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,13 @@ export function createContainer(
248248
tag: RootTag,
249249
hydrate: boolean,
250250
hydrationCallbacks: null | SuspenseHydrationCallbacks,
251-
strictModeLevelOverride: null | number,
252251
concurrentUpdatesByDefaultOverride: null | boolean,
253252
): OpaqueRoot {
254253
return createFiberRoot(
255254
containerInfo,
256255
tag,
257256
hydrate,
258257
hydrationCallbacks,
259-
strictModeLevelOverride,
260258
concurrentUpdatesByDefaultOverride,
261259
);
262260
}

packages/react-reconciler/src/ReactFiberReconciler.old.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,13 @@ export function createContainer(
248248
tag: RootTag,
249249
hydrate: boolean,
250250
hydrationCallbacks: null | SuspenseHydrationCallbacks,
251-
strictModeLevelOverride: null | number,
252251
concurrentUpdatesByDefaultOverride: null | boolean,
253252
): OpaqueRoot {
254253
return createFiberRoot(
255254
containerInfo,
256255
tag,
257256
hydrate,
258257
hydrationCallbacks,
259-
strictModeLevelOverride,
260258
concurrentUpdatesByDefaultOverride,
261259
);
262260
}

packages/react-reconciler/src/ReactFiberRoot.new.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export function createFiberRoot(
9898
tag: RootTag,
9999
hydrate: boolean,
100100
hydrationCallbacks: null | SuspenseHydrationCallbacks,
101-
strictModeLevelOverride: null | number,
102101
concurrentUpdatesByDefaultOverride: null | boolean,
103102
): FiberRoot {
104103
const root: FiberRoot = (new FiberRootNode(containerInfo, tag, hydrate): any);
@@ -110,7 +109,6 @@ export function createFiberRoot(
110109
// stateNode is any.
111110
const uninitializedFiber = createHostRootFiber(
112111
tag,
113-
strictModeLevelOverride,
114112
concurrentUpdatesByDefaultOverride,
115113
);
116114
root.current = uninitializedFiber;

packages/react-reconciler/src/ReactFiberRoot.old.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export function createFiberRoot(
9898
tag: RootTag,
9999
hydrate: boolean,
100100
hydrationCallbacks: null | SuspenseHydrationCallbacks,
101-
strictModeLevelOverride: null | number,
102101
concurrentUpdatesByDefaultOverride: null | boolean,
103102
): FiberRoot {
104103
const root: FiberRoot = (new FiberRootNode(containerInfo, tag, hydrate): any);
@@ -110,7 +109,6 @@ export function createFiberRoot(
110109
// stateNode is any.
111110
const uninitializedFiber = createHostRootFiber(
112111
tag,
113-
strictModeLevelOverride,
114112
concurrentUpdatesByDefaultOverride,
115113
);
116114
root.current = uninitializedFiber;

packages/react-reconciler/src/__tests__/DebugTracing-test.internal.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ describe('DebugTracing', () => {
282282
expect(logs).toEqual([
283283
`group: ⚛️ render (${DEFAULT_LANE_STRING})`,
284284
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
285-
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
286285
`groupEnd: ⚛️ render (${DEFAULT_LANE_STRING})`,
287286
]);
288287
});
@@ -366,7 +365,6 @@ describe('DebugTracing', () => {
366365
expect(logs).toEqual([
367366
`group: ⚛️ render (${DEFAULT_LANE_STRING})`,
368367
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`,
369-
`log: ⚛️ Example updated state (${DEFAULT_LANE_STRING})`, // debugRenderPhaseSideEffectsForStrictMode
370368
`groupEnd: ⚛️ render (${DEFAULT_LANE_STRING})`,
371369
]);
372370
});

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,7 @@ describe('ReactHooksWithNoopRenderer', () => {
520520
</>,
521521
);
522522
expect(() =>
523-
expect(Scheduler).toFlushAndYield(
524-
__DEV__
525-
? ['Foo [0]', 'Bar', 'Foo [2]']
526-
: ['Foo [0]', 'Bar', 'Foo [1]'],
527-
),
523+
expect(Scheduler).toFlushAndYield(['Foo [0]', 'Bar', 'Foo [1]']),
528524
).toErrorDev([
529525
'Cannot update a component (`Foo`) while rendering a ' +
530526
'different component (`Bar`). To locate the bad setState() call inside `Bar`',
@@ -539,11 +535,7 @@ describe('ReactHooksWithNoopRenderer', () => {
539535
<Bar triggerUpdate={true} />
540536
</>,
541537
);
542-
expect(Scheduler).toFlushAndYield(
543-
__DEV__
544-
? ['Foo [2]', 'Bar', 'Foo [4]']
545-
: ['Foo [1]', 'Bar', 'Foo [2]'],
546-
);
538+
expect(Scheduler).toFlushAndYield(['Foo [1]', 'Bar', 'Foo [2]']);
547539
});
548540
});
549541

@@ -1765,16 +1757,11 @@ describe('ReactHooksWithNoopRenderer', () => {
17651757
return <Text text={'Count: ' + count} />;
17661758
}
17671759

1768-
// we explicitly wait for missing act() warnings here since
1769-
// it's a lot harder to simulate this condition inside an act scope
1770-
expect(() => {
1771-
ReactNoop.render(<Counter count={0} />, () =>
1772-
Scheduler.unstable_yieldValue('Sync effect'),
1773-
);
1774-
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1775-
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1776-
}).toErrorDev(['An update to Counter ran an effect']);
1777-
1760+
ReactNoop.render(<Counter count={0} />, () =>
1761+
Scheduler.unstable_yieldValue('Sync effect'),
1762+
);
1763+
expect(Scheduler).toFlushAndYieldThrough(['Count: 0', 'Sync effect']);
1764+
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
17781765
// A flush sync doesn't cause the passive effects to fire.
17791766
// So we haven't added the other update yet.
17801767
act(() => {

0 commit comments

Comments
 (0)