Skip to content

Commit 2b53e76

Browse files
committed
[cleanup] remove enableHostSingletons feature flag
1 parent 51ffd35 commit 2b53e76

28 files changed

+82
-328
lines changed

packages/react-dom-bindings/src/client/ReactDOMComponent.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import {
6969
enableCustomElementPropertySupport,
7070
enableClientRenderFallbackOnTextMismatch,
7171
enableFormActions,
72-
enableHostSingletons,
7372
disableIEWorkarounds,
7473
enableTrustedTypesIntegration,
7574
enableFilterEmptyStringAttributesDOM,
@@ -394,16 +393,15 @@ function setProp(
394393
// show within the <textarea> until it has been focused and blurred again.
395394
// https://github.com/facebook/react/issues/6731#issuecomment-254874553
396395
const canSetTextContent =
397-
(!enableHostSingletons || tag !== 'body') &&
398-
(tag !== 'textarea' || value !== '');
396+
tag !== 'body' && (tag !== 'textarea' || value !== '');
399397
if (canSetTextContent) {
400398
setTextContent(domElement, value);
401399
}
402400
} else if (typeof value === 'number') {
403401
if (__DEV__) {
404402
validateTextNesting('' + value, tag);
405403
}
406-
const canSetTextContent = !enableHostSingletons || tag !== 'body';
404+
const canSetTextContent = tag !== 'body';
407405
if (canSetTextContent) {
408406
setTextContent(domElement, '' + value);
409407
}
@@ -2822,7 +2820,7 @@ export function diffHydratedProperties(
28222820
// we can get away with it.
28232821
// Host singletons get their children appended and don't use the text
28242822
// content mechanism.
2825-
if (!enableHostSingletons || tag !== 'body') {
2823+
if (tag !== 'body') {
28262824
domElement.textContent = (children: any);
28272825
}
28282826
}

packages/react-dom-bindings/src/client/ReactDOMComponentTree.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ import {
3434

3535
import {getParentSuspenseInstance} from './ReactFiberConfigDOM';
3636

37-
import {
38-
enableScopeAPI,
39-
enableFloat,
40-
enableHostSingletons,
41-
} from 'shared/ReactFeatureFlags';
37+
import {enableScopeAPI, enableFloat} from 'shared/ReactFeatureFlags';
4238

4339
const randomKey = Math.random().toString(36).slice(2);
4440
const internalInstanceKey = '__reactFiber$' + randomKey;
@@ -180,7 +176,7 @@ export function getInstanceFromNode(node: Node): Fiber | null {
180176
tag === HostText ||
181177
tag === SuspenseComponent ||
182178
(enableFloat ? tag === HostHoistable : false) ||
183-
(enableHostSingletons ? tag === HostSingleton : false) ||
179+
tag === HostSingleton ||
184180
tag === HostRoot
185181
) {
186182
return inst;
@@ -200,7 +196,7 @@ export function getNodeFromInstance(inst: Fiber): Instance | TextInstance {
200196
if (
201197
tag === HostComponent ||
202198
(enableFloat ? tag === HostHoistable : false) ||
203-
(enableHostSingletons ? tag === HostSingleton : false) ||
199+
tag === HostSingleton ||
204200
tag === HostText
205201
) {
206202
// In Fiber this, is just the state node right now. We assume it will be

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ import {
9292
enableCreateEventHandleAPI,
9393
enableScopeAPI,
9494
enableFloat,
95-
enableHostSingletons,
9695
enableTrustedTypesIntegration,
9796
enableFormActions,
9897
enableAsyncActions,
@@ -939,32 +938,18 @@ export function unhideTextInstance(
939938
}
940939

941940
export function clearContainer(container: Container): void {
942-
if (enableHostSingletons) {
943-
const nodeType = container.nodeType;
944-
if (nodeType === DOCUMENT_NODE) {
945-
clearContainerSparingly(container);
946-
} else if (nodeType === ELEMENT_NODE) {
947-
switch (container.nodeName) {
948-
case 'HEAD':
949-
case 'HTML':
950-
case 'BODY':
951-
clearContainerSparingly(container);
952-
return;
953-
default: {
954-
container.textContent = '';
955-
}
956-
}
957-
}
958-
} else {
959-
if (container.nodeType === ELEMENT_NODE) {
960-
// We have refined the container to Element type
961-
const element: Element = (container: any);
962-
element.textContent = '';
963-
} else if (container.nodeType === DOCUMENT_NODE) {
964-
// We have refined the container to Document type
965-
const doc: Document = (container: any);
966-
if (doc.documentElement) {
967-
doc.removeChild(doc.documentElement);
941+
const nodeType = container.nodeType;
942+
if (nodeType === DOCUMENT_NODE) {
943+
clearContainerSparingly(container);
944+
} else if (nodeType === ELEMENT_NODE) {
945+
switch (container.nodeName) {
946+
case 'HEAD':
947+
case 'HTML':
948+
case 'BODY':
949+
clearContainerSparingly(container);
950+
return;
951+
default: {
952+
container.textContent = '';
968953
}
969954
}
970955
}
@@ -1053,7 +1038,7 @@ export function canHydrateInstance(
10531038
const element: Element = (instance: any);
10541039
const anyProps = (props: any);
10551040
if (element.nodeName.toLowerCase() !== type.toLowerCase()) {
1056-
if (!inRootOrSingleton || !enableHostSingletons) {
1041+
if (!inRootOrSingleton) {
10571042
// Usually we error for mismatched tags.
10581043
if (
10591044
enableFormActions &&
@@ -1067,7 +1052,7 @@ export function canHydrateInstance(
10671052
}
10681053
}
10691054
// In root or singleton parents we skip past mismatched instances.
1070-
} else if (!inRootOrSingleton || !enableHostSingletons) {
1055+
} else if (!inRootOrSingleton) {
10711056
// Match
10721057
if (
10731058
enableFormActions &&
@@ -1212,7 +1197,7 @@ export function canHydrateTextInstance(
12121197
) {
12131198
// If we have extra hidden inputs, we don't mismatch. This allows us to
12141199
// embed extra form data in the original form.
1215-
} else if (!inRootOrSingleton || !enableHostSingletons) {
1200+
} else if (!inRootOrSingleton) {
12161201
return null;
12171202
}
12181203
const nextInstance = getNextHydratableSibling(instance);
@@ -1230,7 +1215,7 @@ export function canHydrateSuspenseInstance(
12301215
inRootOrSingleton: boolean,
12311216
): null | SuspenseInstance {
12321217
while (instance.nodeType !== COMMENT_NODE) {
1233-
if (!inRootOrSingleton || !enableHostSingletons) {
1218+
if (!inRootOrSingleton) {
12341219
return null;
12351220
}
12361221
const nextInstance = getNextHydratableSibling(instance);
@@ -1292,7 +1277,7 @@ export function canHydrateFormStateMarker(
12921277
inRootOrSingleton: boolean,
12931278
): null | FormStateMarkerInstance {
12941279
while (instance.nodeType !== COMMENT_NODE) {
1295-
if (!inRootOrSingleton || !enableHostSingletons) {
1280+
if (!inRootOrSingleton) {
12961281
return null;
12971282
}
12981283
const nextInstance = getNextHydratableSibling(instance);
@@ -1501,9 +1486,7 @@ export function shouldDeleteUnhydratedTailInstances(
15011486
parentType: string,
15021487
): boolean {
15031488
return (
1504-
(enableHostSingletons ||
1505-
(parentType !== 'head' && parentType !== 'body')) &&
1506-
(!enableFormActions || (parentType !== 'form' && parentType !== 'button'))
1489+
!enableFormActions || (parentType !== 'form' && parentType !== 'button')
15071490
);
15081491
}
15091492

packages/react-dom-bindings/src/events/DOMPluginEventSystem.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
enableCreateEventHandleAPI,
5454
enableScopeAPI,
5555
enableFloat,
56-
enableHostSingletons,
5756
enableFormActions,
5857
} from 'shared/ReactFeatureFlags';
5958
import {
@@ -637,7 +636,7 @@ export function dispatchEventForPluginEventSystem(
637636
parentTag === HostComponent ||
638637
parentTag === HostText ||
639638
(enableFloat ? parentTag === HostHoistable : false) ||
640-
(enableHostSingletons ? parentTag === HostSingleton : false)
639+
parentTag === HostSingleton
641640
) {
642641
node = ancestorInst = parentNode;
643642
continue mainLoop;
@@ -695,7 +694,7 @@ export function accumulateSinglePhaseListeners(
695694
if (
696695
(tag === HostComponent ||
697696
(enableFloat ? tag === HostHoistable : false) ||
698-
(enableHostSingletons ? tag === HostSingleton : false)) &&
697+
tag === HostSingleton) &&
699698
stateNode !== null
700699
) {
701700
lastHostComponent = stateNode;
@@ -809,7 +808,7 @@ export function accumulateTwoPhaseListeners(
809808
if (
810809
(tag === HostComponent ||
811810
(enableFloat ? tag === HostHoistable : false) ||
812-
(enableHostSingletons ? tag === HostSingleton : false)) &&
811+
tag === HostSingleton) &&
813812
stateNode !== null
814813
) {
815814
const currentTarget = stateNode;
@@ -843,11 +842,7 @@ function getParent(inst: Fiber | null): Fiber | null {
843842
// events to their parent. We could also go through parentNode on the
844843
// host node but that wouldn't work for React Native and doesn't let us
845844
// do the portal feature.
846-
} while (
847-
inst &&
848-
inst.tag !== HostComponent &&
849-
(!enableHostSingletons ? true : inst.tag !== HostSingleton)
850-
);
845+
} while (inst && inst.tag !== HostComponent && inst.tag !== HostSingleton);
851846
if (inst) {
852847
return inst;
853848
}
@@ -916,7 +911,7 @@ function accumulateEnterLeaveListenersForEvent(
916911
if (
917912
(tag === HostComponent ||
918913
(enableFloat ? tag === HostHoistable : false) ||
919-
(enableHostSingletons ? tag === HostSingleton : false)) &&
914+
tag === HostSingleton) &&
920915
stateNode !== null
921916
) {
922917
const currentTarget = stateNode;

packages/react-dom-bindings/src/events/plugins/EnterLeaveEventPlugin.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
} from '../../client/ReactDOMComponentTree';
2525
import {accumulateEnterLeaveTwoPhaseListeners} from '../DOMPluginEventSystem';
2626

27-
import {enableHostSingletons} from 'shared/ReactFeatureFlags';
2827
import {
2928
HostComponent,
3029
HostSingleton,
@@ -110,9 +109,7 @@ function extractEvents(
110109
const tag = to.tag;
111110
if (
112111
to !== nearestMounted ||
113-
(tag !== HostComponent &&
114-
(!enableHostSingletons ? true : tag !== HostSingleton) &&
115-
tag !== HostText)
112+
(tag !== HostComponent && tag !== HostSingleton && tag !== HostText)
116113
) {
117114
to = null;
118115
}

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

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6124,7 +6124,7 @@ body {
61246124
);
61256125
});
61266126

6127-
// @gate enableFloat && enableHostSingletons && enableClientRenderFallbackOnTextMismatch
6127+
// @gate enableFloat && enableClientRenderFallbackOnTextMismatch
61286128
it('retains styles even when a new html, head, and/body mount', async () => {
61296129
await act(() => {
61306130
const {pipe} = renderToPipeableStream(
@@ -6176,58 +6176,7 @@ body {
61766176
);
61776177
});
61786178

6179-
// @gate enableFloat && !enableHostSingletons
6180-
it('retains styles even when a new html, head, and/body mount - without HostSingleton', async () => {
6181-
await act(() => {
6182-
const {pipe} = renderToPipeableStream(
6183-
<html>
6184-
<head />
6185-
<body>
6186-
<link rel="stylesheet" href="foo" precedence="foo" />
6187-
<link rel="stylesheet" href="bar" precedence="bar" />
6188-
server
6189-
</body>
6190-
</html>,
6191-
);
6192-
pipe(writable);
6193-
});
6194-
const errors = [];
6195-
ReactDOMClient.hydrateRoot(
6196-
document,
6197-
<html>
6198-
<head>
6199-
<link rel="stylesheet" href="qux" precedence="qux" />
6200-
<link rel="stylesheet" href="foo" precedence="foo" />
6201-
</head>
6202-
<body>client</body>
6203-
</html>,
6204-
{
6205-
onRecoverableError(error) {
6206-
errors.push(error.message);
6207-
},
6208-
},
6209-
);
6210-
await expect(async () => {
6211-
await waitForAll([]);
6212-
}).toErrorDev(
6213-
[
6214-
'Warning: Text content did not match. Server: "server" Client: "client"',
6215-
'Warning: An error occurred during hydration. The server HTML was replaced with client content in <#document>.',
6216-
],
6217-
{withoutStack: 1},
6218-
);
6219-
expect(getMeaningfulChildren(document)).toEqual(
6220-
<html>
6221-
<head>
6222-
<link rel="stylesheet" href="qux" data-precedence="qux" />
6223-
<link rel="stylesheet" href="foo" data-precedence="foo" />
6224-
</head>
6225-
<body>client</body>
6226-
</html>,
6227-
);
6228-
});
6229-
6230-
// @gate enableFloat && enableHostSingletons
6179+
// @gate enableFloat
62316180
it('retains styles in head through head remounts', async () => {
62326181
const root = ReactDOMClient.createRoot(document);
62336182
root.render(
@@ -8036,7 +7985,7 @@ background-color: green;
80367985
]);
80377986
});
80387987

8039-
// @gate enableFloat && enableHostSingletons && (enableClientRenderFallbackOnTextMismatch || !__DEV__)
7988+
// @gate enableFloat && (enableClientRenderFallbackOnTextMismatch || !__DEV__)
80407989
it('can render a title before a singleton even if that singleton clears its contents', async () => {
80417990
await act(() => {
80427991
const {pipe} = renderToPipeableStream(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ describe('ReactDOMRoot', () => {
375375
await waitForAll([]);
376376
container.innerHTML = '';
377377

378-
if (gate(flags => flags.enableFloat || flags.enableHostSingletons)) {
378+
if (gate(flags => flags.enableFloat)) {
379379
// When either of these flags are on this validation is turned off so we
380380
// expect there to be no warnings
381381
root.render(<div>Hi</div>);

0 commit comments

Comments
 (0)