Skip to content

Commit fdeba78

Browse files
kassensAndyPengc12
authored andcommitted
[cleanup] remove enableHostSingletons feature flag (facebook#27583)
The flag is enabled everywhere, I think we can remove it now.
1 parent cd7dd49 commit fdeba78

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
@@ -6202,7 +6202,7 @@ body {
62026202
);
62036203
});
62046204

6205-
// @gate enableFloat && enableHostSingletons && enableClientRenderFallbackOnTextMismatch
6205+
// @gate enableFloat && enableClientRenderFallbackOnTextMismatch
62066206
it('retains styles even when a new html, head, and/body mount', async () => {
62076207
await act(() => {
62086208
const {pipe} = renderToPipeableStream(
@@ -6254,58 +6254,7 @@ body {
62546254
);
62556255
});
62566256

6257-
// @gate enableFloat && !enableHostSingletons
6258-
it('retains styles even when a new html, head, and/body mount - without HostSingleton', async () => {
6259-
await act(() => {
6260-
const {pipe} = renderToPipeableStream(
6261-
<html>
6262-
<head />
6263-
<body>
6264-
<link rel="stylesheet" href="foo" precedence="foo" />
6265-
<link rel="stylesheet" href="bar" precedence="bar" />
6266-
server
6267-
</body>
6268-
</html>,
6269-
);
6270-
pipe(writable);
6271-
});
6272-
const errors = [];
6273-
ReactDOMClient.hydrateRoot(
6274-
document,
6275-
<html>
6276-
<head>
6277-
<link rel="stylesheet" href="qux" precedence="qux" />
6278-
<link rel="stylesheet" href="foo" precedence="foo" />
6279-
</head>
6280-
<body>client</body>
6281-
</html>,
6282-
{
6283-
onRecoverableError(error) {
6284-
errors.push(error.message);
6285-
},
6286-
},
6287-
);
6288-
await expect(async () => {
6289-
await waitForAll([]);
6290-
}).toErrorDev(
6291-
[
6292-
'Warning: Text content did not match. Server: "server" Client: "client"',
6293-
'Warning: An error occurred during hydration. The server HTML was replaced with client content in <#document>.',
6294-
],
6295-
{withoutStack: 1},
6296-
);
6297-
expect(getMeaningfulChildren(document)).toEqual(
6298-
<html>
6299-
<head>
6300-
<link rel="stylesheet" href="qux" data-precedence="qux" />
6301-
<link rel="stylesheet" href="foo" data-precedence="foo" />
6302-
</head>
6303-
<body>client</body>
6304-
</html>,
6305-
);
6306-
});
6307-
6308-
// @gate enableFloat && enableHostSingletons
6257+
// @gate enableFloat
63096258
it('retains styles in head through head remounts', async () => {
63106259
const root = ReactDOMClient.createRoot(document);
63116260
root.render(
@@ -8114,7 +8063,7 @@ background-color: green;
81148063
]);
81158064
});
81168065

8117-
// @gate enableFloat && enableHostSingletons && (enableClientRenderFallbackOnTextMismatch || !__DEV__)
8066+
// @gate enableFloat && (enableClientRenderFallbackOnTextMismatch || !__DEV__)
81188067
it('can render a title before a singleton even if that singleton clears its contents', async () => {
81198068
await act(() => {
81208069
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)