Skip to content

Commit 4494f2a

Browse files
authored
[Float] add support for scripts and other enhancements (#25480)
* float enhance!!! Support preinit as script Support resources from async scripts Support saving the precedence place when rendering the shell There was a significant change to the flushing order of resources which follows the general principal of... 1. stuff that blocks display 2. stuff that we know will be used 3. stuff that was explicitly preloaded As a consequence if you preinit a style now it won't automatically flush in the shell unless you actually depend on it in your tree. To avoid races with precedence order we now emit a tag that saves the place amongst the precedence hierarchy so late insertions still end up where they were intended There is also a novel hydration pathway for certain tags. If you render an async script with an onLoad or onError it will always treat it like an insertion rather than a hydration. * restore preinit style flushing behavior and nits
1 parent 9ecf84e commit 4494f2a

15 files changed

+1397
-495
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
* @flow
88
*/
99

10-
import type {FloatRoot, StyleResource} from './ReactDOMFloatClient';
10+
import type {
11+
FloatRoot,
12+
StyleResource,
13+
ScriptResource,
14+
} from './ReactDOMFloatClient';
1115
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1216
import type {ReactScopeInstance} from 'shared/ReactTypes';
1317
import type {
@@ -48,7 +52,7 @@ const internalContainerInstanceKey = '__reactContainer$' + randomKey;
4852
const internalEventHandlersKey = '__reactEvents$' + randomKey;
4953
const internalEventHandlerListenersKey = '__reactListeners$' + randomKey;
5054
const internalEventHandlesSetKey = '__reactHandles$' + randomKey;
51-
const internalRootNodeStylesSetKey = '__reactStyles$' + randomKey;
55+
const internalRootNodeResourcesKey = '__reactResources$' + randomKey;
5256

5357
export function detachDeletedInstance(node: Instance): void {
5458
// TODO: This function is only called on host components. I don't think all of
@@ -278,10 +282,15 @@ export function doesTargetHaveEventHandle(
278282
return eventHandles.has(eventHandle);
279283
}
280284

281-
export function getStylesFromRoot(root: FloatRoot): Map<string, StyleResource> {
282-
let styles = (root: any)[internalRootNodeStylesSetKey];
283-
if (!styles) {
284-
styles = (root: any)[internalRootNodeStylesSetKey] = new Map();
285+
export function getResourcesFromRoot(
286+
root: FloatRoot,
287+
): {styles: Map<string, StyleResource>, scripts: Map<string, ScriptResource>} {
288+
let resources = (root: any)[internalRootNodeResourcesKey];
289+
if (!resources) {
290+
resources = (root: any)[internalRootNodeResourcesKey] = {
291+
styles: new Map(),
292+
scripts: new Map(),
293+
};
285294
}
286-
return styles;
295+
return resources;
287296
}

0 commit comments

Comments
 (0)