[2.0.3 / main] After hydration, an onSettled write waits for an unrelated browser-only read under its own <Loading>, and a hydrated block disappears meanwhile (regression from rc.21)

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

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bun, javascript, node.js, playwright, typescript

調査の方向性

Start with the bisected regression in @solidjs/signals: commit 9e02d02a (#4865), then compare the behavior with a4b40256 (#5085) using the self-contained repro in App.jsx, build.mjs, server.mjs, and run.mjs. Run repro.sh across the listed versions and inspect the transaction and verdict-lane behavior described in the report. Done means the browser-only read no longer delays the onSettled write and the hydrated overview remains visible while that read is pending.

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

説明

Describe the bug

After hydration, a write made in onSettled waits for a browser-only async read that the write's own branch opens. That read sits under its own <Loading>. On 2.0.0-rc.22 through 2.0.3 the write never lands. On main (after #5085) it lands, but only when that unrelated read answers. Until then, a block the server rendered and the client hydrated disappears from the page.

It needs this shape:

  • a server-adopted live source list (an async iterable branded Symbol.for("solid.LiveSource"), as @solidjs/router's liveQuery brands one), so the browser re-runs it after hydration;
  • id = createMemo(() => latest(list)?.[0]);
  • a server-rendered live read keyed on id, shown through a <Show> with a nested <Show>;
  • a browser-only (ssrSource: "client") slow read keyed on id, mounted by an onSettled flag under its own <Loading>.

Each of these is needed. On main it passes without the nested <Show>, with id reading list() instead of latest(list), or when either read is not keyed on id. An intermediate memo between latest() and the readers (#4965's scope) is not needed. The narrowed accessor isn't either: a plain nested <Show> is enough.

<Show> has to stay a component. The repro compiles with @solidjs/compiler's dev: true, as our app's build does. With the production default (lowerShow, see #5092) the <Show>s are inlined and it passes.

Your Example Website or App

Self-contained repro below: SSR with renderToStream, hydration in Chromium (Playwright). Bun bundles the client.

Steps to Reproduce the Bug or Issue

App.jsx:

import { Show, Loading, createMemo, createSignal, latest, onSettled } from "solid-js";

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// A live source branded the way @solidjs/router's liveQuery brands one: the server
// serializes its first value; after hydration the browser re-runs the compute, and
// this one answers `ms` later and stays open.
async function* gen(value, ms) {
  if (typeof window !== "undefined") await sleep(ms);
  yield value;
  await new Promise(() => {});
}
function live(value, ms) {
  const it = gen(value, ms);
  it[Symbol.for("solid.LiveSource")] = true;
  return it;
}

export function App() {
  const list = createMemo(() => live(["a"], 200));
  const id = createMemo(() => latest(list)?.[0]);
  // Server-rendered, keyed on `id`.
  const overview = createMemo(() => (id() ? live(5, 100) : undefined));
  // Browser-only and slow, keyed on `id`: answers 1 s after it is asked.
  const inbox = createMemo(() => (id() ? live([], 1000) : []), { ssrSource: "client", lazy: true });
  const [hydrated, setHydrated] = createSignal(false);
  onSettled(() => {
    setHydrated(true);
  });
  return (
    <main>
      <i id="hydrated">{hydrated() ? "yes" : "no"}</i>
      <Show when={hydrated()}>
        <Loading fallback={null}>
          <Show when={inbox().length > 0}>unread</Show>
        </Loading>
      </Show>
      <Show when={overview()}>
        <Show when={overview() > 1}>
          <b id="overview">{overview()}</b>
        </Show>
      </Show>
    </main>
  );
}

build.mjs:

// Compiles App.jsx for the server and the browser with @solidjs/compiler (`dev: true`
// keeps <Show> a component), renders it with renderToStream, bundles the client.
import { transform } from "@solidjs/compiler";
import { readFileSync, writeFileSync } from "node:fs";
import { execSync } from "node:child_process";
const src = readFileSync("App.jsx", "utf8");
for (const generate of ["ssr", "dom"])
  writeFileSync(`App.${generate}.mjs`, transform(src, { filename: "App.jsx", generate, hydratable: true, dev: true }).code);
writeFileSync("client-entry.mjs", `import { hydrate } from "@solidjs/web";
import { App } from "./App.dom.mjs";
hydrate(() => App(), document.getElementById("root"));\n`);
execSync("bun build client-entry.mjs --target=browser --production --outfile=client.js", { stdio: "ignore" });
execSync("node server.mjs > index.html", { stdio: "inherit", shell: true });

server.mjs:

import { renderToStream, generateHydrationScript } from "@solidjs/web";
import { App } from "./App.ssr.mjs";
let html = "";
await new Promise((resolve) => renderToStream(() => App()).pipe({ write: (c) => { html += c; }, end: resolve }));
process.stdout.write(`<!doctype html><html><head>${generateHydrationScript()}</head><body><div id="root">${html}</div><script src="client.js"></script></body></html>`);

run.mjs:

// Opens index.html in Chromium and prints each change of <main>'s text, with its time.
import { chromium } from "playwright";
const browser = await chromium.launch({ channel: "chromium" });
const page = await browser.newPage();
await page.addInitScript(() => {
  window.changes = [];
  const t0 = performance.now();
  new MutationObserver(() => {
    const text = document.querySelector("main")?.textContent;
    if (text !== undefined && text !== window.last) {
      window.last = text;
      window.changes.push(`${Math.round(performance.now() - t0)} ms: ${text}`);
    }
  }).observe(document, { subtree: true, childList: true, characterData: true });
});
await page.goto(new URL("./index.html", import.meta.url).href);
await page.waitForTimeout(2000);
console.log((await page.evaluate(() => window.changes)).join("\n"));
await browser.close();

repro.sh:

#!/bin/bash
# usage: ./repro.sh <solid-js/@solidjs/web version> [@solidjs/signals version]
set -e
v=$1; s=${2:-$1}; d=v-$v-signals-$s; rm -rf $d; mkdir $d; cp App.jsx build.mjs server.mjs run.mjs $d/; cd $d
cat > package.json <<J
{ "private": true, "type": "module", "overrides": { "@solidjs/signals": "$s" } }
J
bun add -E solid-js@$v @solidjs/web@$v @solidjs/signals@$s @solidjs/[email protected] [email protected] >/dev/null 2>&1
node build.mjs && echo "solid-js/web $v, signals $s:" && node run.mjs

The overrides keep one @solidjs/signals: [email protected] asks for ^2.0.0-rc.21, which otherwise installs a nested 2.0.3 beside the pinned one (as #5073 noted).

$ ./repro.sh 2.0.0-rc.21
2 ms: no5
126 ms: yes5

$ ./repro.sh 2.0.0-rc.22        # the same for rc.23, 2.0.0, 2.0.1, 2.0.2 and 2.0.3
1 ms: no5

$ ./repro.sh 2.0.0-rc.21 2.0.0-rc.22
1 ms: no5

main: the 2.0.3 install with packages/signals/dist built at 99db9bce swapped in:

3 ms: no5
131 ms: no
1031 ms: yes5
Expected behavior

As on 2.0.0-rc.21: #hydrated reads yes when the list's re-run answers (~120 ms), and #overview stays on the page throughout. The browser-only read is under its own <Loading fallback={null}>, so the write that mounts it should not wait for its answer.

Actual:

  • 2.0.0-rc.22 through 2.0.3: #hydrated stays no forever.
  • main (99db9bce, and a4b40256 / #5085 alone): #hydrated reads yes only when the browser-only read answers (~1 s). From ~130 ms until then, #overview is gone from the page, although the server rendered it and the browser hydrated it.

The same happens with Solid's development runtime (--conditions=development). Only the compile matters (<Show> kept as a component).

Screenshots or Videos

No response

Platform
  • OS: macOS 26
  • Browser: Chrome for Testing (Playwright 1.65.1, channel: "chromium")
  • Version: solid-js, @solidjs/web, @solidjs/signals 2.0.3 and main (99db9bce); @solidjs/compiler 2.0.2; Node 26.13.1; Bun
Additional context

Bisect. The regression is in @solidjs/signals: solid-js/@solidjs/web rc.21 with @solidjs/signals rc.22 fails. With @solidjs/signals built from source under solid-js/@solidjs/web rc.21:

signals build #hydrated
dc33de68 yes at ~120 ms
08959165 (#4792) yes at ~120 ms
b4647d52 yes at ~120 ms
9e02d02a (#4865) never

That is the commit #4965 bisected to. a4b40256 (#5085, for #5073) turns "never" into "only when the unrelated read answers", and #overview disappears meanwhile.

In a larger app on main. Our app has this shape (a workspace list → latest() → a scope every Studio read is keyed on, and several onSettled-mounted browser-only reads). With @solidjs/signals from main:

  • the 2.0.3 symptoms (a hydrated list drawn twice, aria-busy that never clears) are gone;
  • an engage dialog mounted by an onSettled flag (<Show when={mounted()}><Loading><Show when={key()} keyed>) does not open within 30 s;
  • Stale read from <Show>. is thrown into the root error boundary on every signed-in page. The read is a nested <Show when={box().rows$().length > 0 || box().unread$() > 0}>, inside <Show when={hydrated() && inbox}>{(box) => <Loading>…</Loading>}</Show>, where hydrated is set in onSettled.

We traced the throw in the development build:

  1. The outer <Show> opens in the flush that holds the onSettled writes (a held transaction T). The inner <Show>'s condition value is born in T.
  2. When the workspace list's re-run answers, the inner when reads rows$ and unread$. These are sync memos whose verdict posture is inherited (page$ → scope$ → activeId$, which calls latest()), and none probes on its own. #4792's branch in read() forces a recompute of each. They are pending on the browser-only page$, and the status propagation (notify… → list) seats the reader in the verdict lane L that activeId$ started.
  3. The inner condition then reads condition value, and #4792's branch forces it too. That pass runs as L's (passLane is L, not the flush's transaction). L's world does not hold T's hydrated = true, so the outer <Show>'s guard sees the committed false and throws. It throws again from the frame shortly after, still before T lands.

A standalone repro of the throw isn't included: every reduction of it lost the throw, while the hold above survived. The repro above is the same hold, seen from a block that isn't narrowed.

Workarounds. We found none that is plain Solid 2 code. Reading list() instead of latest(list) changes what a refresh of the list does (every untracked reader of the scope would throw while it re-asks). Making id probe on its own, #4965's workaround, is already the case here.

Related: #4965 (same first bad commit), #5073 / #5085 (the fix that turns "never" into this).

主要言語
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 を短くまとめたダイジェスト。