Skip to content

Commit 1f7a2f5

Browse files
authored
[Float] support title tags as Resources (#25508)
Adds a category of Resources of type `head` which will be used to track the tags that go into the <head> Currently only implements for `<title>`. titles are keyed off their textContent so each time the title changes a new resource will be created. Currently insertion is done by prepending in the <head>. The argument here is that the newest title should "win" if there are multiple rendered. This also helps when a navigation or update causes a server rendered title to hang around but it is not the most recent one.
1 parent c635807 commit 1f7a2f5

12 files changed

+801
-112
lines changed

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

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

10-
import type {
11-
FloatRoot,
12-
StyleResource,
13-
ScriptResource,
14-
} from './ReactDOMFloatClient';
10+
import type {FloatRoot, RootResources} from './ReactDOMFloatClient';
1511
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1612
import type {ReactScopeInstance} from 'shared/ReactTypes';
1713
import type {
@@ -53,6 +49,7 @@ const internalEventHandlersKey = '__reactEvents$' + randomKey;
5349
const internalEventHandlerListenersKey = '__reactListeners$' + randomKey;
5450
const internalEventHandlesSetKey = '__reactHandles$' + randomKey;
5551
const internalRootNodeResourcesKey = '__reactResources$' + randomKey;
52+
const internalResourceMarker = '__reactMarker$' + randomKey;
5653

5754
export function detachDeletedInstance(node: Instance): void {
5855
// TODO: This function is only called on host components. I don't think all of
@@ -282,15 +279,22 @@ export function doesTargetHaveEventHandle(
282279
return eventHandles.has(eventHandle);
283280
}
284281

285-
export function getResourcesFromRoot(
286-
root: FloatRoot,
287-
): {styles: Map<string, StyleResource>, scripts: Map<string, ScriptResource>} {
282+
export function getResourcesFromRoot(root: FloatRoot): RootResources {
288283
let resources = (root: any)[internalRootNodeResourcesKey];
289284
if (!resources) {
290285
resources = (root: any)[internalRootNodeResourcesKey] = {
291286
styles: new Map(),
292287
scripts: new Map(),
288+
head: new Map(),
293289
};
294290
}
295291
return resources;
296292
}
293+
294+
export function isMarkedResource(node: Node): boolean {
295+
return !!(node: any)[internalResourceMarker];
296+
}
297+
298+
export function markNodeAsResource(node: Node) {
299+
(node: any)[internalResourceMarker] = true;
300+
}

0 commit comments

Comments
 (0)