diff --git a/package.json b/package.json index 4b3c846..a604163 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/bfanger/svelte-preprocess-react.git" }, - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "type": "module", "scripts": { diff --git a/src/lib/sveltify.svelte.ts b/src/lib/sveltify.svelte.ts index 907e427..744d41a 100644 --- a/src/lib/sveltify.svelte.ts +++ b/src/lib/sveltify.svelte.ts @@ -187,14 +187,23 @@ function single( (ReactWrapper as any)(anchorOrPayload, $$props); if (standalone && !client) { + let renderError: Error | undefined; if (renderToString && sharedRoot) { setPayload(anchorOrPayload); - const html = renderToString( - React.createElement(Bridge, { node: sharedRoot }), - ); - const source = { html }; - applyPortals(anchorOrPayload, sharedRoot, source); + try { + const html = renderToString( + React.createElement(Bridge, { node: sharedRoot }), + ); + const source = { html }; + applyPortals(anchorOrPayload, sharedRoot, source); + } catch (err) { + renderError = (err as Error) ?? new Error("Unknown error"); + sharedRoot = undefined; + } setPayload(undefined); + if (renderError) { + throw renderError; + } } } } @@ -236,25 +245,28 @@ function applyPortal( source.html, ); } catch { - // The React component, didn't render the childrenThe rendering of children can be conditional. + // The React component didn't render the children, the rendering of children can be conditional. } } - const portal = extract( - ``, - ``, - source.html, - ); - - source.html = portal.outerRemoved; try { + const portal = extract( + ``, + ``, + source.html, + ); + + source.html = portal.outerRemoved; $$payload.out = inject( ``, "", portal.innerHtml, $$payload.out, ); - } catch (err: any) { - console.warn(err.message); + } catch (err) { + if (!node.parent) { + throw err; + } + // Nested component didn't render, could be suspense or conditional rendering. } } diff --git a/src/routes/broken/+page.svelte b/src/routes/broken/+page.svelte new file mode 100644 index 0000000..822a7c6 --- /dev/null +++ b/src/routes/broken/+page.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/routes/suspense/+page.svelte b/src/routes/suspense/+page.svelte new file mode 100644 index 0000000..28eb14f --- /dev/null +++ b/src/routes/suspense/+page.svelte @@ -0,0 +1,19 @@ + + + + +