Skip to content

Commit 9a029c0

Browse files
committed
Simplify the inserted scripts
We can assume that there are no text nodes before the template tag so this simplifies the script that finds the comment node. It should be the direct previous child.
1 parent c67471f commit 9a029c0

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,19 +1543,14 @@ export function writeEndSegment(
15431543
//
15441544
// function clientRenderBoundary(suspenseBoundaryID) {
15451545
// // Find the fallback's first element.
1546-
// let suspenseNode = document.getElementById(suspenseBoundaryID);
1547-
// if (!suspenseNode) {
1546+
// const suspenseIdNode = document.getElementById(suspenseBoundaryID);
1547+
// if (!suspenseIdNode) {
15481548
// // The user must have already navigated away from this tree.
15491549
// // E.g. because the parent was hydrated.
15501550
// return;
15511551
// }
1552-
// // Find the boundary around the fallback. This might include text nodes.
1553-
// do {
1554-
// suspenseNode = suspenseNode.previousSibling;
1555-
// } while (
1556-
// suspenseNode.nodeType !== COMMENT_NODE ||
1557-
// suspenseNode.data !== SUSPENSE_PENDING_START_DATA
1558-
// );
1552+
// // Find the boundary around the fallback. This is always the previous node.
1553+
// const suspenseNode = suspenseIdNode.previousSibling;
15591554
// // Tag it to be client rendered.
15601555
// suspenseNode.data = SUSPENSE_FALLBACK_START_DATA;
15611556
// // Tell React to retry it if the parent already hydrated.
@@ -1566,24 +1561,19 @@ export function writeEndSegment(
15661561
//
15671562
// function completeBoundary(suspenseBoundaryID, contentID) {
15681563
// // Find the fallback's first element.
1569-
// let suspenseNode = document.getElementById(suspenseBoundaryID);
1564+
// const suspenseIdNode = document.getElementById(suspenseBoundaryID);
15701565
// const contentNode = document.getElementById(contentID);
15711566
// // We'll detach the content node so that regardless of what happens next we don't leave in the tree.
15721567
// // This might also help by not causing recalcing each time we move a child from here to the target.
15731568
// contentNode.parentNode.removeChild(contentNode);
1574-
// if (!suspenseNode) {
1569+
// if (!suspenseIdNode) {
15751570
// // The user must have already navigated away from this tree.
15761571
// // E.g. because the parent was hydrated. That's fine there's nothing to do
15771572
// // but we have to make sure that we already deleted the container node.
15781573
// return;
15791574
// }
1580-
// // Find the boundary around the fallback. This might include text nodes.
1581-
// do {
1582-
// suspenseNode = suspenseNode.previousSibling;
1583-
// } while (
1584-
// suspenseNode.nodeType !== COMMENT_NODE ||
1585-
// suspenseNode.data !== SUSPENSE_PENDING_START_DATA
1586-
// );
1575+
// // Find the boundary around the fallback. This is always the previous node.
1576+
// const suspenseNode = suspenseIdNode.previousSibling;
15871577
//
15881578
// // Clear all the existing children. This is complicated because
15891579
// // there can be embedded Suspense boundaries in the fallback.
@@ -1646,11 +1636,11 @@ export function writeEndSegment(
16461636
// }
16471637

16481638
const completeSegmentFunction =
1649-
'function $RS(b,f){var a=document.getElementById(b),c=document.getElementById(f);for(a.parentNode.removeChild(a);a.firstChild;)c.parentNode.insertBefore(a.firstChild,c);c.parentNode.removeChild(c)}';
1639+
'function $RS(a,b){a=document.getElementById(a);b=document.getElementById(b);for(a.parentNode.removeChild(a);a.firstChild;)b.parentNode.insertBefore(a.firstChild,b);b.parentNode.removeChild(b)}';
16501640
const completeBoundaryFunction =
1651-
'function $RC(b,f){var a=document.getElementById(b),c=document.getElementById(f);c.parentNode.removeChild(c);if(a){do a=a.previousSibling;while(8!==a.nodeType||"$?"!==a.data);var h=a.parentNode,d=a.nextSibling,g=0;do{if(d&&8===d.nodeType){var e=d.data;if("/$"===e)if(0===g)break;else g--;else"$"!==e&&"$?"!==e&&"$!"!==e||g++}e=d.nextSibling;h.removeChild(d);d=e}while(d);for(;c.firstChild;)h.insertBefore(c.firstChild,d);a.data="$";a._reactRetry&&a._reactRetry()}}';
1641+
'function $RC(a,b){a=document.getElementById(a);b=document.getElementById(b);b.parentNode.removeChild(b);if(a){a=a.previousSibling;var f=a.parentNode,c=a.nextSibling,e=0;do{if(c&&8===c.nodeType){var d=c.data;if("/$"===d)if(0===e)break;else e--;else"$"!==d&&"$?"!==d&&"$!"!==d||e++}d=c.nextSibling;f.removeChild(c);c=d}while(c);for(;b.firstChild;)f.insertBefore(b.firstChild,c);a.data="$";a._reactRetry&&a._reactRetry()}}';
16521642
const clientRenderFunction =
1653-
'function $RX(b){if(b=document.getElementById(b)){do b=b.previousSibling;while(8!==b.nodeType||"$?"!==b.data);b.data="$!";b._reactRetry&&b._reactRetry()}}';
1643+
'function $RX(a){if(a=document.getElementById(a))a=a.previousSibling,a.data="$!",a._reactRetry&&a._reactRetry()}';
16541644

16551645
const completeSegmentScript1Full = stringToPrecomputedChunk(
16561646
'<script>' + completeSegmentFunction + ';$RS("',

0 commit comments

Comments
 (0)