Skip to content

Commit 665126a

Browse files
authored
Save bytes on hydration 2.0 (#4894)
* Save bytes on hydration 2.0 * Check truthy instead * We already assign to newvnode._dom in catch * Always remove comments from excessDomChildren * Save 1 byte by not casting
1 parent 18432f9 commit 665126a

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/diff/index.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ export function diff(
7575
if (newVNode.constructor != UNDEFINED) return NULL;
7676

7777
// If the previous diff bailed out, resume creating/hydrating.
78-
if (oldVNode._flags & MODE_SUSPENDED) {
79-
isHydrating = !!(oldVNode._flags & MODE_HYDRATE);
80-
if (oldVNode._component._excess) {
81-
excessDomChildren = oldVNode._component._excess;
82-
oldDom = newVNode._dom = oldVNode._dom = excessDomChildren[0];
83-
oldVNode._component._excess = null;
84-
}
78+
if (
79+
oldVNode._flags & MODE_SUSPENDED &&
80+
// @ts-expect-error This is 1 or 0 (true or false)
81+
(isHydrating = oldVNode._flags & MODE_HYDRATE)
82+
) {
83+
excessDomChildren = oldVNode._component._excess;
84+
oldDom = excessDomChildren[0];
85+
oldVNode._component._excess = NULL;
8586
}
8687

8788
if ((tmp = options._diff)) tmp(newVNode);
@@ -311,7 +312,7 @@ export function diff(
311312
if (isHydrating || excessDomChildren != NULL) {
312313
if (e.then) {
313314
let commentMarkersToFind = 0,
314-
done = false;
315+
done;
315316

316317
newVNode._flags |= isHydrating
317318
? MODE_HYDRATE | MODE_SUSPENDED
@@ -329,21 +330,22 @@ export function diff(
329330
// We exclude the open and closing marker from
330331
// the future excessDomChildren but any nested one
331332
// needs to be included for future suspensions.
332-
if (child.nodeType == 8 && child.data == '$s') {
333-
if (commentMarkersToFind > 0) {
334-
newVNode._component._excess.push(child);
335-
}
336-
commentMarkersToFind++;
337-
excessDomChildren[i] = NULL;
338-
} else if (child.nodeType == 8 && child.data == '/$s') {
339-
commentMarkersToFind--;
340-
if (commentMarkersToFind > 0) {
341-
newVNode._component._excess.push(child);
333+
if (child.nodeType == 8) {
334+
if (child.data == '$s') {
335+
if (commentMarkersToFind) {
336+
newVNode._component._excess.push(child);
337+
}
338+
commentMarkersToFind++;
339+
} else if (child.data == '/$s') {
340+
commentMarkersToFind--;
341+
if (commentMarkersToFind) {
342+
newVNode._component._excess.push(child);
343+
}
344+
done = commentMarkersToFind == 0;
345+
oldDom = excessDomChildren[i];
342346
}
343-
done = commentMarkersToFind === 0;
344-
oldDom = excessDomChildren[i];
345347
excessDomChildren[i] = NULL;
346-
} else if (commentMarkersToFind > 0) {
348+
} else if (commentMarkersToFind) {
347349
newVNode._component._excess.push(child);
348350
excessDomChildren[i] = NULL;
349351
}

0 commit comments

Comments
 (0)