Skip to content
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

Slightly improve performance of hydration. #15998

Merged
merged 3 commits into from Jun 27, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -670,44 +670,40 @@ export function registerSuspenseInstanceRetry(
instance._reactRetry = callback;
}

export function getNextHydratableSibling(
instance: HydratableInstance,
): null | HydratableInstance {
let node = instance.nextSibling;
function getNextHydratable(node) {
// Skip non-hydratable nodes.
while (
node &&
node.nodeType !== ELEMENT_NODE &&
node.nodeType !== TEXT_NODE &&
(!enableSuspenseServerRenderer ||
node.nodeType !== COMMENT_NODE ||
((node: any).data !== SUSPENSE_START_DATA &&
(node: any).data !== SUSPENSE_PENDING_START_DATA &&
(node: any).data !== SUSPENSE_FALLBACK_START_DATA))
) {
node = node.nextSibling;
for (; node != null; node = node.nextSibling) {
const nodeType = node.nodeType;
if (nodeType === ELEMENT_NODE || nodeType === TEXT_NODE) {
break;
}
if (enableSuspenseServerRenderer) {
if (nodeType === COMMENT_NODE) {
break;

This comment has been minimized.

Copy link
@sebmarkbage

sebmarkbage Aug 4, 2019

Member

This should actually have been if (nodeType !== COMMENT_NODE) continue. Logic is hard. :)

This comment has been minimized.

Copy link
@acdlite

acdlite Aug 5, 2019

Member

Also, test coverage is hard :D

}
const nodeData = (node: any).data;
if (
nodeData === SUSPENSE_START_DATA ||
nodeData === SUSPENSE_FALLBACK_START_DATA ||
nodeData === SUSPENSE_PENDING_START_DATA
) {
break;
}
}
}
return (node: any);
}

export function getNextHydratableSibling(
instance: HydratableInstance,
): null | HydratableInstance {
return getNextHydratable(instance.nextSibling);
}

export function getFirstHydratableChild(
parentInstance: Container | Instance,
): null | HydratableInstance {
let next = parentInstance.firstChild;
// Skip non-hydratable nodes.
while (
next &&
next.nodeType !== ELEMENT_NODE &&
next.nodeType !== TEXT_NODE &&
(!enableSuspenseServerRenderer ||
next.nodeType !== COMMENT_NODE ||
((next: any).data !== SUSPENSE_START_DATA &&
(next: any).data !== SUSPENSE_FALLBACK_START_DATA &&
(next: any).data !== SUSPENSE_PENDING_START_DATA))
) {
next = next.nextSibling;
}
return (next: any);
return getNextHydratable(parentInstance.firstChild);
}

export function hydrateInstance(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.