@@ -227,7 +227,9 @@ export function transformStreamWithRouter(
227227 // between-chunk text buffer; keep bounded to avoid unbounded memory
228228 let leftover = ''
229229
230- // captured closing tags from </body> onward
230+ // Captured closing tags that must stay after router-injected scripts.
231+ // Some renderers, like Solid, continue streaming boundary chunks after
232+ // </html>; those chunks should still pass through before these tags.
231233 let pendingClosingTags = ''
232234
233235 // conservative cap: enough to hold any partial closing tag + a bit
@@ -404,9 +406,11 @@ export function transformStreamWithRouter(
404406 }
405407 }
406408
407- // If we already saw </body>, everything else is part of tail; buffer it.
409+ // If we already saw </body>, keep streaming app chunks before the
410+ // captured closing tags instead of buffering them until render end.
408411 if ( pendingClosingTags ) {
409- pendingClosingTags += chunkString
412+ flushPendingRouterHtml ( )
413+ safeEnqueue ( chunkString )
410414 leftover = ''
411415 continue
412416 }
@@ -419,9 +423,11 @@ export function transformStreamWithRouter(
419423 htmlEndIndex !== - 1 &&
420424 bodyEndIndex < htmlEndIndex
421425 ) {
422- pendingClosingTags = chunkString . slice ( bodyEndIndex )
426+ const htmlEndTagEnd = htmlEndIndex + HTML_END_TAG . length
427+ pendingClosingTags = chunkString . slice ( bodyEndIndex , htmlEndTagEnd )
423428 safeEnqueue ( chunkString . slice ( 0 , bodyEndIndex ) )
424429 flushPendingRouterHtml ( )
430+ safeEnqueue ( chunkString . slice ( htmlEndTagEnd ) )
425431 leftover = ''
426432 continue
427433 }
0 commit comments