Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.

fix(solid-start): answer each Convex query once per server render - #5

Merged
ethan-huo merged 1 commit into
mainfrom
convex-ssr-dedupe
Sep 30, 2026
Merged

ethan-huo merged 1 commit into
mainfrom
convex-ssr-dedupe

Conversation

@ethan-huo

Copy link
Copy Markdown
Contributor

问题

querySource 在服务端每次调用都走 locals.convex.query(),而 per-request reader 每次都发一个新的 HTTP 查询、返回一个新的 pending Promise。Solid 2 SSR 通过反复重跑 <Loading> 的 children 来发现边界,每一轮都拿到新的 pending 值,某些页面下永不收敛(did not converge after 10001 passes),Worker 超 CPU 限额,HTML 流在 shell 之后被截断。只在 production build 出现,vite dev 不复现。

证据:celados/delta 的 whiteboard /studio/account 白屏,修复见 https://github.com/celados/delta/pull/160 。本 PR 把同一修复移植回模板。

改动

  • web/src/lib/convex-server.ts:per-request 的 answers Map,按 函数名 + convexToJson(args) 去重,同一次渲染里同一个问题返回同一个 Promise。convex.ts 无需改动。
  • web/src/lib/convex-server.test.tsx:回归测试(同一问题返回同一 Promise、只发一次 HTTP 请求;不同问题各自请求)。

Solid 版本未动(rc.10)。

验证

  • bun run check 通过(format / lint / typecheck / web 15 tests / extension 24 tests / deadcode)。
  • 反向对照:去掉缓存读取后新测试失败(expected Promise{…} to be Promise{…} // Object.is equality),恢复后通过。
  • 未做:production build 下的真实浏览器渲染验证(模板当前页面没有触发不收敛的路由)。

Solid 2 resolves a <Loading> on the server by re-running its children; the
per-request reader issued a new HTTP query, and a new pending promise, on
every pass, so boundary discovery could fail to converge (10001 passes), the
Worker exceeded its CPU limit and the document was cut off after the shell.
Production builds only. Evidence: celados/delta#160.

Why: templates/solid-start/web/src/lib/convex-server.ts#createServerConvex | query must return the same promise per function+args for the request; a fresh promise per call makes SSR <Loading> discovery never converge (prod build only)
@ethan-huo
ethan-huo merged commit c1d3c00 into main Sep 30, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant