Skip to content

Commit

Permalink
Improve general code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeurer committed Jun 26, 2019
1 parent 5b24cfd commit 3c8fbb0
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,45 +670,40 @@ export function registerSuspenseInstanceRetry(
instance._reactRetry = callback;
}

function isHydratableNode(node: Node) {
const nodeType = node.nodeType;
if (nodeType === ELEMENT_NODE || nodeType === TEXT_NODE) {
return true;
}
if (enableSuspenseServerRenderer) {
if (nodeType === COMMENT_NODE) {
return true;
function getNextHydratable(node: Node) {
// Skip non-hydratable nodes.
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;
}
const nodeData = (node: any).data;
if (
nodeData === SUSPENSE_START_DATA ||
nodeData === SUSPENSE_FALLBACK_START_DATA ||
nodeData === SUSPENSE_PENDING_START_DATA
) {
break;
}
}
const nodeData = (node: any).data;
return (
nodeData === SUSPENSE_START_DATA ||
nodeData === SUSPENSE_FALLBACK_START_DATA ||
nodeData === SUSPENSE_PENDING_START_DATA
);
}
return false;
return (node: any);
}

export function getNextHydratableSibling(
instance: HydratableInstance,
): null | HydratableInstance {
let node = instance.nextSibling;
// Skip non-hydratable nodes.
while (node != null && !isHydratableNode(node)) {
node = node.nextSibling;
}
return (node: any);
return getNextHydratable(instance.nextSibling);
}

export function getFirstHydratableChild(
parentInstance: Container | Instance,
): null | HydratableInstance {
let node = parentInstance.firstChild;
// Skip non-hydratable nodes.
while (node != null && !isHydratableNode(node)) {
node = node.nextSibling;
}
return (node: any);
return getNextHydratable(parentInstance.firstChild);
}

export function hydrateInstance(
Expand Down

0 comments on commit 3c8fbb0

Please sign in to comment.