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;

0 commit comments

Comments
 (0)