@@ -66,61 +66,71 @@ export default function sveltify<P>(
6666 return `<ssr-portal${ current . length - 1 } />` ;
6767 }
6868 current = [ ] ;
69- const contexts = getAllContexts ( ) ;
70- const html = $$render . call ( Slot , result , { } , bindings , slots , context ) ;
71- const leaf = ! slots . default && current . length === 0 ;
69+ try {
70+ const contexts = getAllContexts ( ) ;
71+ const html = $$render . call (
72+ Slot ,
73+ result ,
74+ { } ,
75+ bindings ,
76+ slots ,
77+ context
78+ ) ;
79+ const leaf = ! slots . default && current . length === 0 ;
7280
73- const vdom = leaf
74- ? React . createElement (
75- reactComponent as React . FunctionComponent ,
76- props
81+ const vdom = leaf
82+ ? React . createElement (
83+ reactComponent as React . FunctionComponent ,
84+ props
85+ )
86+ : React . createElement (
87+ reactComponent as React . FunctionComponent ,
88+ props ,
89+ [
90+ React . createElement ( "svelte-slot" , {
91+ key : "svelte-slot" ,
92+ style : { display : "contents" } ,
93+ dangerouslySetInnerHTML : { __html : html } ,
94+ } ) ,
95+ ...current . map ( ( child , i ) =>
96+ React . createElement (
97+ `ssr-portal${ i } ` ,
98+ { key : `ssr-portal${ i } ` } ,
99+ React . createElement ( child . reactComponent , child . props )
100+ )
101+ ) ,
102+ ]
103+ ) ;
104+ let rendered = renderToString (
105+ React . createElement (
106+ SvelteToReactContext . Provider ,
107+ {
108+ value : context || contexts ,
109+ } ,
110+ vdom
77111 )
78- : React . createElement (
79- reactComponent as React . FunctionComponent ,
80- props ,
81- [
82- React . createElement ( "svelte-slot" , {
83- key : "svelte-slot" ,
84- style : { display : "contents" } ,
85- dangerouslySetInnerHTML : { __html : html } ,
86- } ) ,
87- ...current . map ( ( child , i ) =>
88- React . createElement (
89- `ssr-portal${ i } ` ,
90- { key : `ssr-portal${ i } ` } ,
91- React . createElement ( child . reactComponent , child . props )
92- )
93- ) ,
94- ]
95- ) ;
96- let rendered = renderToString (
97- React . createElement (
98- SvelteToReactContext . Provider ,
99- {
100- value : context || contexts ,
101- } ,
102- vdom
103- )
104- ) ;
105- current . forEach ( ( _ , i ) => {
106- const start = `<ssr-portal${ i } >` ;
107- const end = `</ssr-portal${ i } >` ;
108- const startPosition = rendered . indexOf ( start ) ;
109- const endPosition = rendered . indexOf ( end ) ;
110- let content = "" ;
111- if ( startPosition !== - 1 ) {
112- content = rendered . substring (
113- startPosition + start . length ,
114- endPosition
115- ) ;
116- rendered =
117- rendered . substring ( 0 , startPosition ) +
118- rendered . substring ( endPosition + end . length ) ;
119- }
120- rendered = rendered . replace ( `<ssr-portal${ i } />` , content ) ;
121- } ) ;
122- current = undefined ;
123- return rendered ;
112+ ) ;
113+ current . forEach ( ( _ , i ) => {
114+ const start = `<ssr-portal${ i } >` ;
115+ const end = `</ssr-portal${ i } >` ;
116+ const startPosition = rendered . indexOf ( start ) ;
117+ const endPosition = rendered . indexOf ( end ) ;
118+ let content = "" ;
119+ if ( startPosition !== - 1 ) {
120+ content = rendered . substring (
121+ startPosition + start . length ,
122+ endPosition
123+ ) ;
124+ rendered =
125+ rendered . substring ( 0 , startPosition ) +
126+ rendered . substring ( endPosition + end . length ) ;
127+ }
128+ rendered = rendered . replace ( `<ssr-portal${ i } />` , content ) ;
129+ } ) ;
130+ return rendered ;
131+ } finally {
132+ current = undefined ;
133+ }
124134 } ,
125135 } as any ;
126136 }
0 commit comments