Repository navigation
Description
Since #4303, when an async read under a <Loading> rejects during renderToStream, the <Errored> around it draws its fallback on the server and the hydrating client adopts it, but only when the <Loading> is the <Errored>'s whole content. With markup between them (<Errored><b><Loading>…</Loading></b></Errored>) or a sibling beside the <Loading>, the server sends a blank instead: before the shell, the shell keeps <b></b>; after it, an empty <template id="…" e></template>. The fallback only appears once the client hydrates, and never without JS.
Playground
Open in the Solid playground (2.0.4). The page loads solid-js and @solidjs/web a second time as their server builds (https://esm.sh/…@2.0.4?conditions=worker), runs renderToStream in the page with the server template helpers, and prints the stream for each case. Nothing to click. The standalone Node repro below gives the same output.
Repro
With solid-js@2.0.4 and @solidjs/web@2.0.4 installed, run node no-compiler.mjs <direct|element> <ms>. It uses the server build and the server template helpers, so no compiler is needed. ms is when the read rejects: 200 is after the shell, 1 is before it.
import { createMemo, Loading, Errored, createComponent } from "solid-js";
import { renderToStream, ssr, escape, markSafeError } from "@solidjs/web";
const [shape = "element", ms = "200"] = process.argv.slice(2);
let reject;
const p = new Promise((_, j) => (reject = j));
p.catch(() => {});
function App() {
const user = createMemo(() => p);
const loading = () =>
createComponent(Loading, {
fallback: ssr(["<i>loading</i>"]),
get children() { return ssr(["<u>", "</u>"], () => escape(user().name)); }
});
return ssr(["<main>", "</main>"], createComponent(Errored, {
fallback: e => ssr(["<p>failed: ", "</p>"], escape(e().message)),
// direct: <Errored><Loading>…; element: <Errored><b><Loading>…
get children() { return shape === "direct" ? loading() : ssr(["<b>", "</b>"], loading()); }
}));
}
renderToStream(() => createComponent(App, {})).pipe({
write: c => console.log(c.replace(/<script>[\s\S]*?<\/script>/g, "")),
end() {}
});
setTimeout(() => reject(markSafeError(new Error("no user"))), Number(ms));Expected
Every shape should end with the error fallback in place of the <Errored>'s content. That is what direct gets and what a client render shows: <main><p>failed: no user</p></main>. Before the shell, nothing has been sent yet, so the fallback can go straight into the shell.
Actual
On 2.0.4, with <script> tags removed:
$ node no-compiler.mjs direct 200
<main><template id="pl-100"></template><i>loading</i><!--pl-100--></main>
<template id="100" e><p>failed: no user</p></template>
$ node no-compiler.mjs element 200
<main><b><template id="pl-100"></template><i>loading</i><!--pl-100--></b></main>
<template id="100" e></template>
$ node no-compiler.mjs direct 1
<main><p>failed: no user</p></main>
$ node no-compiler.mjs element 1
<main><b></b></main>
Compiled JSX gives the same output (with _hk ids), whether the element is written inline or returned by a component. A sibling beside the <Loading> does too (checked on main 50a4bfd). A component that returns the <Loading> alone is fine. In Chromium without a client bundle, element stays <main><b></b></main>.
Versions: 2.0.4, 2.0.0, 2.0.0-rc.23, rc.22 and rc.21 (npm) and main (ad1f561, 50a4bfd) all give the output above. No version tested draws the fallback for the nested shape, so this is not a regression.
Why this is a leftover
- fix(solid): an Errored around a failing streamed Loading draws its fallback on the server #4303's "Before" describes this blank as the bug it fixed ("Until hydration the browser showed neither the loading fallback nor the error fallback"). Its "After" then keeps it, without a reason: "With markup between the two boundaries (
<Errored><section><Loading>), the position stays blank and the client renders the failure, as before." - The hydration harness pins only the after-shell blank, and describes it without saying why:
scenarios.tsx:1585(PostflushRejectionNested). No test pins the before-shell blank. - For server components the rule is already the opposite: "the position shows what the SERVER rendered for the outcome, never a blank, never a client-invented state" (
hydration.ts:396).
Cause
The server createErrorBoundary's renderOutcome (signals.ts:4409) answers the failing <Loading> only when its content is exactly that <Loading>'s placeholder. Otherwise failFragment settles the fragment as failed with no content:
- After the shell, that settled fragment is the empty
<template e>above. - Before the shell, the placeholder is inlined away as
"". The<Errored>'s markup is already in the held shell as a finished string, and no error is recorded at the<Errored>.
Since #4318, a nested <Errored> can already replace its markup with its fallback when that markup sits inside a <Loading> fragment that is still pending (ESCALATE, FragmentContainer.region). The held shell does not get the same treatment.
Proposed fixes
- (a) Before the shell flush, when nothing has been sent yet. Draw the
<Errored>'s fallback in the shell in place of its whole markup. This reuses the Errored fallback whose async hole rejects is dropped inside a pending outer Loading #4316 region machinery (escalated,FragmentContainer.region), with the unflushed shell treated as one more container. The error is serialized at the<Errored>id, so the client adopts the fallback as it does for the direct shape. To be conservative, this happens only when the fallback's markup is ready synchronously. Otherwise the behaviour stays as it is today, so the shell is never delayed. A branch with this change and tests exists and can be opened as a PR. - (b) After the shell flush. The
<Errored>'s markup is already out, and an<Errored>emits no markers of its own. This would need markers around the<Errored>region in the shell and a streamed region swap. Open questions: the hydration scaffolding for a client that hydrated mid-stream, leftoverpl-*placeholders and markers, and reveal groups. This is an enhancement, not part of (a). - (c) If neither is wanted, document the limit under
<Errored>and<Loading>and indocumentation/solid-2.0/12-ssr-http.md.
Related
- [2.0 / next] SSR: a boundary that fails through an async read renders no error fallback outside server-component scope, and hydration asks again #4287 (closed): the direct shape, fixed by fix(solid): an Errored around a failing streamed Loading draws its fallback on the server #4303.
- fix(solid): an Errored around a failing streamed Loading draws its fallback on the server #4303 (merged): "The fallback is drawn only for the direct shape; nested markup stays blank."
- Errored fallback whose async hole rejects is dropped inside a pending outer Loading #4316 / fix(solid): an Errored fallback's own failure goes to the next boundary up; its wait is budgeted (#4316, #4317) #4318: a fallback's own failure goes to the next boundary up. fix(solid): an Errored fallback's own failure goes to the next boundary up; its wait is budgeted (#4316, #4317) #4318 added the escalation path that fix (a) reuses.
Activity
fix(solid, web): an Errored's fallback reaches the page when a nested…
fix(web): the page refuses an after-shell Errored range the HTML pars…
fix(solid, web): an Errored's fallback reaches the page when a nested…
fix(web): the page refuses an after-shell Errored range the HTML pars…