Skip to content

Commit 7b25b96

Browse files
authored
[Fizz/Float] Float for stylesheet resources (#25243)
* [Fizz/Float] Float for stylesheet resources This commit implements Float in Fizz and on the Client. The initial set of supported APIs is roughly 1. Convert certain stylesheets into style Resources when opting in with precedence prop 2. Emit preloads for stylesheets and explicit preload tags 3. Dedupe all Resources by href 4. Implement ReactDOM.preload() to allow for imperative preloading 5. Implement ReactDOM.preinit() to allow for imperative preinitialization Currently supports 1. style Resources (link rel "stylesheet") 2. font Resources (preload as "font") later updates will include support for scripts and modules
1 parent d061e6e commit 7b25b96

File tree

57 files changed

+7070
-634
lines changed

Some content is hidden

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

57 files changed

+7070
-634
lines changed

packages/react-art/src/ReactARTHostConfig.js

+9
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration';
243243
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes';
244244
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors';
245245
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMicrotasks';
246+
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoResources';
246247

247248
export function appendInitialChild(parentInstance, child) {
248249
if (typeof child === 'string') {
@@ -455,3 +456,11 @@ export function detachDeletedInstance(node: Instance): void {
455456
export function requestPostPaintCallback(callback: (time: number) => void) {
456457
// noop
457458
}
459+
460+
export function prepareRendererToRender(container: Container): void {
461+
// noop
462+
}
463+
464+
export function resetRendererAfterRender(): void {
465+
// noop
466+
}

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

-12
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import {
7373
enableTrustedTypesIntegration,
7474
enableCustomElementPropertySupport,
7575
enableClientRenderFallbackOnTextMismatch,
76-
enableFloat,
7776
} from 'shared/ReactFeatureFlags';
7877
import {
7978
mediaEventTypes,
@@ -1019,17 +1018,6 @@ export function diffHydratedProperties(
10191018
: getPropertyInfo(propKey);
10201019
if (rawProps[SUPPRESS_HYDRATION_WARNING] === true) {
10211020
// Don't bother comparing. We're ignoring all these warnings.
1022-
} else if (
1023-
enableFloat &&
1024-
tag === 'link' &&
1025-
rawProps.rel === 'stylesheet' &&
1026-
propKey === 'precedence'
1027-
) {
1028-
// @TODO this is a temporary rule while we haven't implemented HostResources yet. This is used to allow
1029-
// for hydrating Resources (at the moment, stylesheets with a precedence prop) by using a data attribute.
1030-
// When we implement HostResources there will be no hydration directly so this code can be deleted
1031-
// $FlowFixMe - Should be inferred as not undefined.
1032-
extraAttributeNames.delete('data-rprec');
10331021
} else if (
10341022
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
10351023
propKey === SUPPRESS_HYDRATION_WARNING ||

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ import type {
2323

2424
import {
2525
HostComponent,
26+
HostResource,
2627
HostText,
2728
HostRoot,
2829
SuspenseComponent,
2930
} from 'react-reconciler/src/ReactWorkTags';
3031

3132
import {getParentSuspenseInstance} from './ReactDOMHostConfig';
3233

33-
import {enableScopeAPI} from 'shared/ReactFeatureFlags';
34+
import {enableScopeAPI, enableFloat} from 'shared/ReactFeatureFlags';
3435

3536
const randomKey = Math.random()
3637
.toString(36)
@@ -166,7 +167,8 @@ export function getInstanceFromNode(node: Node): Fiber | null {
166167
inst.tag === HostComponent ||
167168
inst.tag === HostText ||
168169
inst.tag === SuspenseComponent ||
169-
inst.tag === HostRoot
170+
inst.tag === HostRoot ||
171+
(enableFloat ? inst.tag === HostResource : false)
170172
) {
171173
return inst;
172174
} else {
@@ -181,7 +183,11 @@ export function getInstanceFromNode(node: Node): Fiber | null {
181183
* DOM node.
182184
*/
183185
export function getNodeFromInstance(inst: Fiber): Instance | TextInstance {
184-
if (inst.tag === HostComponent || inst.tag === HostText) {
186+
if (
187+
inst.tag === HostComponent ||
188+
inst.tag === HostText ||
189+
(enableFloat ? inst.tag === HostResource : false)
190+
) {
185191
// In Fiber this, is just the state node right now. We assume it will be
186192
// a host component or host text.
187193
return inst.stateNode;

0 commit comments

Comments
 (0)