Skip to content

Commit

Permalink
Implement renderIntoDocument
Browse files Browse the repository at this point in the history
This commit adds the function renderIntoDocument in react-dom/server and adds the ability to embed the rendered children in the necessary html tags to repereset a full document. this means you can render "<html>...</html>" or "<div>...</div>" and either way the render will emit html, head, and body tags as necessary to describe a valid and complete HTML page.

Like renderIntoContainer, renderIntoDocument provides a stream immediately. While there is a shell of sorts this fucntion will start writing content from the preamble (html and head tags, plus resources that flush in the head) before finishing the shell.

Additionally renderIntoContainer accepts fallback children and fallback bootstrap script options. If the Shell errors the  fallback children will render instead of children. The expectation is that the client will attempt to render fresh on the client.
  • Loading branch information
gnoff committed Jan 18, 2023
1 parent 8e5cd60 commit 3ec1561
Show file tree
Hide file tree
Showing 43 changed files with 1,843 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export type Resources = {
preconnects: Set<LinkResource>,
fontPreloads: Set<PreloadResource>,
// usedImagePreloads: Set<PreloadResource>,
firstPrecedence: string,
firstPrecedenceFlushed: boolean,
precedences: Map<string, Set<StyleResource>>,
usedStylePreloads: Set<PreloadResource>,
scripts: Set<ScriptResource>,
Expand Down Expand Up @@ -161,6 +163,8 @@ export function createResources(): Resources {
preconnects: new Set(),
fontPreloads: new Set(),
// usedImagePreloads: new Set(),
firstPrecedence: '',
firstPrecedenceFlushed: false,
precedences: new Map(),
usedStylePreloads: new Set(),
scripts: new Set(),
Expand Down Expand Up @@ -485,14 +489,17 @@ function createStyleResource(
);
}
}
const {stylesMap, preloadsMap, precedences} = resources;
const {stylesMap, preloadsMap, precedences, firstPrecedence} = resources;

// If this is the first time we've seen this precedence we encode it's position in our set even though
// we don't add the resource to this set yet
let precedenceSet = precedences.get(precedence);
if (!precedenceSet) {
precedenceSet = new Set();
precedences.set(precedence, precedenceSet);
if (!firstPrecedence) {
resources.firstPrecedence = precedence;
}
}

let hint = preloadsMap.get(href);
Expand Down
Loading

0 comments on commit 3ec1561

Please sign in to comment.