[2.0.4] SSR: `<Errored>` sends a blank instead of its fallback when the failing `<Loading>` is not its only content (follow-up to #4287)

オープン
#5,223 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript

調査の方向性

Start with the server createErrorBoundary renderOutcome implementation in packages/solid/src/server/signals.ts:4409 and the PostflushRejectionNested scenario in packages/web/test/harness/scenarios.tsx:1585. Compare the held-shell behavior with the existing ESCALATE and FragmentContainer.region path described in the issue. The proposed before-shell fix requires synchronous fallback markup; done means the nested shape renders the error fallback before the shell flush, with tests covering the behavior.

索引モデルが issue の本文から書いたものです。

説明

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 [email protected] and @solidjs/[email protected] 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

  • #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 #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, leftover pl-* 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 in documentation/solid-2.0/12-ssr-http.md.

Related

  • #4287 (closed): the direct shape, fixed by #4303.
  • #4303 (merged): "The fallback is drawn only for the direct shape; nested markup stays blank."
  • #4316 / #4318: a fallback's own failure goes to the next boundary up. #4318 added the escalation path that fix (a) reuses.
主要言語
TypeScript
スター
37k
フォーク
1.2k
平均マージ
8時間 43分
マージ済み PR(30日)
365

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。