Skip to content

Commit bcef5fa

Browse files
committed
Implement HostSingleton Fiber type
1 parent 9f8a98a commit bcef5fa

File tree

52 files changed

+1911
-138
lines changed

Some content is hidden

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

52 files changed

+1911
-138
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ export function createTextNode(
483483
);
484484
}
485485

486+
export function resetProperties(
487+
domElement: Element,
488+
tag: string,
489+
rawProps: Object,
490+
): void {
491+
const attributes = domElement.attributes;
492+
while (attributes.length) {
493+
domElement.removeAttribute(attributes[0].name);
494+
}
495+
setInitialProperties(domElement, tag, rawProps);
496+
}
497+
486498
export function setInitialProperties(
487499
domElement: Element,
488500
tag: string,
@@ -1294,3 +1306,7 @@ export function restoreControlledState(
12941306
return;
12951307
}
12961308
}
1309+
1310+
export function isHostSingletonType(type: string): boolean {
1311+
return type === 'html' || type === 'head' || type === 'body';
1312+
}

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ import type {
2424
import {
2525
HostComponent,
2626
HostResource,
27+
HostSingleton,
2728
HostText,
2829
HostRoot,
2930
SuspenseComponent,
3031
} from 'react-reconciler/src/ReactWorkTags';
3132

32-
import {getParentSuspenseInstance} from './ReactDOMHostConfig';
33+
import {
34+
getParentSuspenseInstance,
35+
supportsSingletons,
36+
} from './ReactDOMHostConfig';
3337

34-
import {enableScopeAPI, enableFloat} from 'shared/ReactFeatureFlags';
38+
import {
39+
enableScopeAPI,
40+
enableFloat,
41+
enableHostSingletons,
42+
} from 'shared/ReactFeatureFlags';
3543

3644
const randomKey = Math.random()
3745
.toString(36)
@@ -167,12 +175,16 @@ export function getInstanceFromNode(node: Node): Fiber | null {
167175
(node: any)[internalInstanceKey] ||
168176
(node: any)[internalContainerInstanceKey];
169177
if (inst) {
178+
const tag = inst.tag;
170179
if (
171-
inst.tag === HostComponent ||
172-
inst.tag === HostText ||
173-
inst.tag === SuspenseComponent ||
174-
inst.tag === HostRoot ||
175-
(enableFloat ? inst.tag === HostResource : false)
180+
tag === HostComponent ||
181+
tag === HostText ||
182+
tag === SuspenseComponent ||
183+
tag === HostRoot ||
184+
(enableFloat ? tag === HostResource : false) ||
185+
(enableHostSingletons && supportsSingletons
186+
? tag === HostSingleton
187+
: false)
176188
) {
177189
return inst;
178190
} else {
@@ -187,10 +199,12 @@ export function getInstanceFromNode(node: Node): Fiber | null {
187199
* DOM node.
188200
*/
189201
export function getNodeFromInstance(inst: Fiber): Instance | TextInstance {
202+
const tag = inst.tag;
190203
if (
191-
inst.tag === HostComponent ||
192-
inst.tag === HostText ||
193-
(enableFloat ? inst.tag === HostResource : false)
204+
tag === HostComponent ||
205+
tag === HostText ||
206+
(enableFloat ? tag === HostResource : false) ||
207+
(enableHostSingletons && supportsSingletons ? tag === HostSingleton : false)
194208
) {
195209
// In Fiber this, is just the state node right now. We assume it will be
196210
// a host component or host text.

0 commit comments

Comments
 (0)