Skip to content

[Fizz] implement renderIntoContainer #25703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type BaseResource = {
flushed: boolean,
};

export type LinkTagResource = PreloadResource | StyleResource | LinkResource;
export type Resource = PreloadResource | StyleResource | ScriptResource;
export type HeadResource =
| TitleResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
import {
clientRenderBoundary,
completeBoundaryWithStyles,
completeContainerWithStyles,
completeBoundary,
completeContainer,
completeSegment,
} from './fizz-instruction-set/ReactDOMFizzInstructionSetExternalRuntime';

if (!window.$RC) {
// TODO: Eventually remove, we currently need to set these globals for
// compatibility with ReactDOMFizzInstructionSet
window.$RC = completeBoundary;
window.$RM = new Map();
}

if (document.readyState === 'loading') {
if (document.body != null) {
installFizzInstrObserver(document.body);
Expand Down Expand Up @@ -74,34 +69,47 @@ function installFizzInstrObserver(target /*: Node */) {
}

function handleNode(node_ /*: Node */) {
// $FlowFixMe[incompatible-cast]
if (node_.nodeType !== 1 || !(node_ /*: HTMLElement*/).dataset) {
if (
node_.nodeType !== 1 ||
// $FlowFixMe[incompatible-cast]
!(node_ /*: HTMLElement*/).dataset
) {
return;
}
// $FlowFixMe[incompatible-cast]
const node = (node_ /*: HTMLElement*/);
const dataset = node.dataset;
if (dataset['rxi'] != null) {
clientRenderBoundary(
dataset['bid'],

if (dataset['ix'] != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - would we expect / handle any of these instruction functions to throw here? I noticed a try-catch in completeContainer, but couldn't find what might throw in that function. Other instruction functions don't look like they would throw either

We should add a try-catch here if other functions can potentially throw (and React is expected to keep rendering). Inline scripts isolate failures, but the external runtime may skip processing further instructions / MutationRecords if one errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I ended up removing the throw but not the wrapping try catch. Good call on handling it here though, we probably should not actually throw and just return from completeContainer

node.remove();
return clientRenderBoundary(
dataset['ix'],
dataset['dgst'],
dataset['msg'],
dataset['stck'],
);
} else if (dataset['is'] != null) {
node.remove();
return completeSegment(dataset['is'], dataset['p']);
} else if (dataset['ir'] != null) {
node.remove();
} else if (dataset['rri'] != null) {
// Convert styles here, since its type is Array<Array<string>>
completeBoundaryWithStyles(
dataset['bid'],
dataset['sid'],
JSON.parse(dataset['sty']),
return completeBoundaryWithStyles(
dataset['ir'],
dataset['s'],
JSON.parse(dataset['r']),
);
} else if (dataset['ib'] != null) {
node.remove();
} else if (dataset['rci'] != null) {
completeBoundary(dataset['bid'], dataset['sid']);
return completeBoundary(dataset['ib'], dataset['s']);
} else if (dataset['ik'] != null) {
node.remove();
} else if (dataset['rsi'] != null) {
completeSegment(dataset['sid'], dataset['pid']);
return completeContainerWithStyles(
dataset['ik'],
dataset['s'],
JSON.parse(dataset['r']),
);
} else if (dataset['ic'] != null) {
node.remove();
return completeContainer(dataset['ic'], dataset['s']);
}
}
Loading