Skip to content

Commit

Permalink
[Float] support title tags as Resources (facebook#25508)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gnoff authored and mofeiZ committed Dec 5, 2022
1 parent a8c497e commit d7f7b6b
Show file tree
Hide file tree
Showing 12 changed files with 802 additions and 112 deletions.
20 changes: 12 additions & 8 deletions packages/react-dom-bindings/src/client/ReactDOMComponentTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
* @flow
*/

import type {
FloatRoot,
StyleResource,
ScriptResource,
} from './ReactDOMFloatClient';
import type {FloatRoot, RootResources} from './ReactDOMFloatClient';
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
import type {ReactScopeInstance} from 'shared/ReactTypes';
import type {
Expand Down Expand Up @@ -53,6 +49,7 @@ const internalEventHandlersKey = '__reactEvents$' + randomKey;
const internalEventHandlerListenersKey = '__reactListeners$' + randomKey;
const internalEventHandlesSetKey = '__reactHandles$' + randomKey;
const internalRootNodeResourcesKey = '__reactResources$' + randomKey;
const internalResourceMarker = '__reactMarker$' + randomKey;

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

export function getResourcesFromRoot(
root: FloatRoot,
): {styles: Map<string, StyleResource>, scripts: Map<string, ScriptResource>} {
export function getResourcesFromRoot(root: FloatRoot): RootResources {
let resources = (root: any)[internalRootNodeResourcesKey];
if (!resources) {
resources = (root: any)[internalRootNodeResourcesKey] = {
styles: new Map(),
scripts: new Map(),
head: new Map(),
};
}
return resources;
}

export function isMarkedResource(node: Node): boolean {
return !!(node: any)[internalResourceMarker];
}

export function markNodeAsResource(node: Node) {
(node: any)[internalResourceMarker] = true;
}
Loading

0 comments on commit d7f7b6b

Please sign in to comment.