Skip to content

Commit 2cf4352

Browse files
authored
Implement HostSingleton Fiber type (#25426)
1 parent aa9988e commit 2cf4352

File tree

54 files changed

+2276
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2276
-193
lines changed

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes';
244244
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors';
245245
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks';
246246
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoResources';
247+
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoSingletons';
247248

248249
export function appendInitialChild(parentInstance, child) {
249250
if (typeof child === 'string') {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
enableTrustedTypesIntegration,
7474
enableCustomElementPropertySupport,
7575
enableClientRenderFallbackOnTextMismatch,
76+
enableHostSingletons,
7677
} from 'shared/ReactFeatureFlags';
7778
import {
7879
mediaEventTypes,
@@ -312,12 +313,17 @@ function setInitialDOMProperties(
312313
// textContent on a <textarea> will cause the placeholder to not
313314
// show within the <textarea> until it has been focused and blurred again.
314315
// https://github.com/facebook/react/issues/6731#issuecomment-254874553
315-
const canSetTextContent = tag !== 'textarea' || nextProp !== '';
316+
const canSetTextContent =
317+
(!enableHostSingletons || tag !== 'body') &&
318+
(tag !== 'textarea' || nextProp !== '');
316319
if (canSetTextContent) {
317320
setTextContent(domElement, nextProp);
318321
}
319322
} else if (typeof nextProp === 'number') {
320-
setTextContent(domElement, '' + nextProp);
323+
const canSetTextContent = !enableHostSingletons || tag !== 'body';
324+
if (canSetTextContent) {
325+
setTextContent(domElement, '' + nextProp);
326+
}
321327
}
322328
} else if (
323329
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ import type {
2525
import {
2626
HostComponent,
2727
HostResource,
28+
HostSingleton,
2829
HostText,
2930
HostRoot,
3031
SuspenseComponent,
3132
} from 'react-reconciler/src/ReactWorkTags';
3233

3334
import {getParentSuspenseInstance} from './ReactDOMHostConfig';
3435

35-
import {enableScopeAPI, enableFloat} from 'shared/ReactFeatureFlags';
36+
import {
37+
enableScopeAPI,
38+
enableFloat,
39+
enableHostSingletons,
40+
} from 'shared/ReactFeatureFlags';
3641

3742
const randomKey = Math.random()
3843
.toString(36)
@@ -169,12 +174,14 @@ export function getInstanceFromNode(node: Node): Fiber | null {
169174
(node: any)[internalInstanceKey] ||
170175
(node: any)[internalContainerInstanceKey];
171176
if (inst) {
177+
const tag = inst.tag;
172178
if (
173-
inst.tag === HostComponent ||
174-
inst.tag === HostText ||
175-
inst.tag === SuspenseComponent ||
176-
inst.tag === HostRoot ||
177-
(enableFloat ? inst.tag === HostResource : false)
179+
tag === HostComponent ||
180+
tag === HostText ||
181+
tag === SuspenseComponent ||
182+
(enableFloat ? tag === HostResource : false) ||
183+
(enableHostSingletons ? tag === HostSingleton : false) ||
184+
tag === HostRoot
178185
) {
179186
return inst;
180187
} else {
@@ -189,10 +196,12 @@ export function getInstanceFromNode(node: Node): Fiber | null {
189196
* DOM node.
190197
*/
191198
export function getNodeFromInstance(inst: Fiber): Instance | TextInstance {
199+
const tag = inst.tag;
192200
if (
193-
inst.tag === HostComponent ||
194-
inst.tag === HostText ||
195-
(enableFloat ? inst.tag === HostResource : false)
201+
tag === HostComponent ||
202+
(enableFloat ? tag === HostResource : false) ||
203+
(enableHostSingletons ? tag === HostSingleton : false) ||
204+
tag === HostText
196205
) {
197206
// In Fiber this, is just the state node right now. We assume it will be
198207
// a host component or host text.

0 commit comments

Comments
 (0)