Skip to content

fix(liveQuery): close the producer after a server render - #754

Open
clean99 wants to merge 1 commit into
solidjs:mainfrom
clean99:contrib/live-query-ssr-producer-finalize
Open

clean99 wants to merge 1 commit into
solidjs:mainfrom
clean99:contrib/live-query-ssr-producer-finalize

Conversation

@clean99

@clean99 clean99 commented Nov 30, 2026

Copy link
Copy Markdown

After a server render, the producer behind a liveQuery is left suspended and its finally never runs. This closes it when the document has taken its first value.

  • Problem: a request-scoped channel calls next() again right after delivering a value. The README's producer shape (a first yield, then for await over a watch) is then parked in its wait when the document takes the first value and leaves, and the closing return() queues behind that pending next(). One suspended producer per rendered page, against "the producer still closes with its last consumer".
  • Change: on request-scoped channels, pull from the producer only while a consumer is waiting for a value, so it rests at its yield, where return() reaches it. Client channels still read ahead. Includes a patch changeset.
  • Compatibility: on the server, a sole consumer that keeps pulling now receives each value in turn instead of latest-wins. A consumer that asks for a further value and then leaves still strands a producer waiting on a change, as it does without a request scope. Closing that needs a signal for the in-process call, the second option in liveQuery SSR: the producer of a live() server function is never finalized after the response ends (the return() queues behind a read-ahead next()) #751.
  • Verification: pnpm exec vitest run --config vitest.config.server.ts test/server/live-query-ssr.spec.ts adds a producer that waits forever after its first yield and checks its finally has run after the last consumer returned (fails on main, passes here), plus a consumer that pulls to the end. Rendering a memo over the query with renderToString and renderToStream inside a request event leaves 1 open producer on main (2 next(), 1 return(), the ratio in the report) and 0 with this change. pnpm run test (762 client and 112 server tests, types), pnpm build and the dist type check pass.

Fixes #751

A request-scoped channel read one value ahead of its consumers. A
producer that waits for a change after its first yield was therefore
parked in that wait when the document took the first value and left;
the closing return() queued behind the pending next() and the
producer's finally never ran, one suspended producer per request.

Pull from the producer on these channels only when a consumer is
waiting for a value, so it rests at its yield, where return() reaches
it. Client channels keep reading ahead.
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 766d3d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

liveQuery SSR: the producer of a live() server function is never finalized after the response ends (the return() queues behind a read-ahead next())

1 participant