@@ -187,14 +187,23 @@ function single<T extends React.FC | React.ComponentClass>(
187187 ( ReactWrapper as any ) ( anchorOrPayload , $$props ) ;
188188
189189 if ( standalone && ! client ) {
190+ let renderError : Error | undefined ;
190191 if ( renderToString && sharedRoot ) {
191192 setPayload ( anchorOrPayload ) ;
192- const html = renderToString (
193- React . createElement ( Bridge , { node : sharedRoot } ) ,
194- ) ;
195- const source = { html } ;
196- applyPortals ( anchorOrPayload , sharedRoot , source ) ;
193+ try {
194+ const html = renderToString (
195+ React . createElement ( Bridge , { node : sharedRoot } ) ,
196+ ) ;
197+ const source = { html } ;
198+ applyPortals ( anchorOrPayload , sharedRoot , source ) ;
199+ } catch ( err ) {
200+ renderError = ( err as Error ) ?? new Error ( "Unknown error" ) ;
201+ sharedRoot = undefined ;
202+ }
197203 setPayload ( undefined ) ;
204+ if ( renderError ) {
205+ throw renderError ;
206+ }
198207 }
199208 }
200209 }
@@ -236,25 +245,28 @@ function applyPortal(
236245 source . html ,
237246 ) ;
238247 } catch {
239- // The React component, didn't render the childrenThe rendering of children can be conditional.
248+ // The React component didn't render the children, the rendering of children can be conditional.
240249 }
241250 }
242- const portal = extract (
243- `<react-portal-source node="${ node . key } " style="display:none">` ,
244- `</react-portal-source>` ,
245- source . html ,
246- ) ;
247-
248- source . html = portal . outerRemoved ;
249251 try {
252+ const portal = extract (
253+ `<react-portal-source node="${ node . key } " style="display:none">` ,
254+ `</react-portal-source>` ,
255+ source . html ,
256+ ) ;
257+
258+ source . html = portal . outerRemoved ;
250259 $$payload . out = inject (
251260 `<svelte-portal-target node="${ node . key } " style="display:contents">` ,
252261 "</svelte-portal-target>" ,
253262 portal . innerHtml ,
254263 $$payload . out ,
255264 ) ;
256- } catch ( err : any ) {
257- console . warn ( err . message ) ;
265+ } catch ( err ) {
266+ if ( ! node . parent ) {
267+ throw err ;
268+ }
269+ // Nested component didn't render, could be suspense or conditional rendering.
258270 }
259271}
260272
0 commit comments