11import type { SSRResult } from '../../../@types/astro' ;
2- import type { RenderInstruction } from './types .js' ;
2+ import type { RenderInstruction } from './instruction .js' ;
33
4+ import { isRenderInstruction } from './instruction.js' ;
45import { HTMLBytes , HTMLString , markHTMLString } from '../escape.js' ;
56import {
67 determineIfNeedsHydrationScript ,
@@ -52,8 +53,8 @@ function stringifyChunk(
5253 result : SSRResult ,
5354 chunk : string | HTMLString | SlotString | RenderInstruction
5455) : string {
55- if ( typeof ( chunk as any ) . type === 'string' ) {
56- const instruction = chunk as RenderInstruction ;
56+ if ( isRenderInstruction ( chunk ) ) {
57+ const instruction = chunk ;
5758 switch ( instruction . type ) {
5859 case 'directive' : {
5960 const { hydration } = instruction ;
@@ -64,8 +65,8 @@ function stringifyChunk(
6465 let prescriptType : PrescriptType = needsHydrationScript
6566 ? 'both'
6667 : needsDirectiveScript
67- ? 'directive'
68- : null ;
68+ ? 'directive'
69+ : null ;
6970 if ( prescriptType ) {
7071 let prescripts = getPrescripts ( result , prescriptType , hydration . directive ) ;
7172 return markHTMLString ( prescripts ) ;
@@ -86,27 +87,24 @@ function stringifyChunk(
8687 return renderAllHeadContent ( result ) ;
8788 }
8889 default : {
89- if ( chunk instanceof Response ) {
90- return '' ;
91- }
9290 throw new Error ( `Unknown chunk type: ${ ( chunk as any ) . type } ` ) ;
9391 }
9492 }
95- } else {
96- if ( isSlotString ( chunk as string ) ) {
97- let out = '' ;
98- const c = chunk as SlotString ;
99- if ( c . instructions ) {
100- for ( const instr of c . instructions ) {
101- out += stringifyChunk ( result , instr ) ;
102- }
93+ } else if ( chunk instanceof Response ) {
94+ return '' ;
95+ } else if ( isSlotString ( chunk as string ) ) {
96+ let out = '' ;
97+ const c = chunk as SlotString ;
98+ if ( c . instructions ) {
99+ for ( const instr of c . instructions ) {
100+ out += stringifyChunk ( result , instr ) ;
103101 }
104- out += chunk . toString ( ) ;
105- return out ;
106102 }
107-
108- return chunk . toString ( ) ;
103+ out += chunk . toString ( ) ;
104+ return out ;
109105 }
106+
107+ return chunk . toString ( ) ;
110108}
111109
112110export function chunkToString ( result : SSRResult , chunk : Exclude < RenderDestinationChunk , Response > ) {
0 commit comments