fix(web): dispose renderToString's root synchronously, committing the response head first (#3385) - #3422
Merged
ryansolid merged 1 commit intoSep 14, 2026
Conversation
… response head first (solidjs#3385)
🦋 Changeset detectedLatest commit: 8ceda85 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
Merging this PR will improve performance by 17.94%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | color-picker: 14 colors (renderToString) |
739.1 µs | 579.8 µs | +27.49% |
| ⚡ | search-results: 50 items (renderToString) |
1.5 ms | 1.4 ms | +9.11% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing Stephen-Psaradellis:fix/render-to-string-sync-dispose (8ceda85) with next (7f6332a)
7 tasks
This was referenced Sep 15, 2026
Closed
Closed
Closed
Closed
This was referenced Sep 16, 2026
Closed
Closed
Closed
Closed
Closed
Open
Special characters in postgres password result in client connections being closed.
permitio/opal#584
Open
"Report a bug" link seems to be inoperative
lairdubois/lairdubois-opencutlist-sketchup-extension#876
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3385.
renderToStringdisposed its root viasetTimeout, so every render in a synchronous loop (benchmarks, batch pre-rendering,Promise.allover many renders) kept its whole reactive graph alive until the next macrotask. The root is now captured and disposed in afinallybefore the function returns;context.traceis cleared there too.The deferral existed so the scope-tied response primitives were not retracted before the head was read. To keep that, the request event's response stub is committed (
commitResponseStub(requestEvent.response, { event })) right afterassembleDocumentand right before the dispose — the same head-freeze point an awaitedrenderToStreamalready uses.httpStatus/httpHeadercleanups are no-ops once the head is committed, so the declarations survive intocreateSSRResponse, which already passes a committed stub through. A render that throws leaves the head uncommitted: its declarations retract with the dispose, as before, and the error path can still write. NoqueueMicrotaskwas needed. This is the first of the two directions @JohannesGezachew laid out in the issue thread; his analysis of which tests a plain sync dispose breaks is what shaped it.One behaviour change to weigh: under a request scope,
renderToStringnow returns withevent.response.committed === true, so a header write betweenrenderToStringreturning andcreateSSRResponsehits the post-commit guard (throws in dev, logs and no-ops in prod). No test in the repo uses that window and an awaitedrenderToStreamalready behaves this way, but integrations (SolidStart) should be checked. Doc comments that namedcreateSSRResponseas therenderToStringcommit point are updated, plus a@solidjs/webpatch changeset.How did you test this change?
From
packages/web, server config (pnpm exec vitest run --config vite.config.server.mjs), basec66130da:test/server/render-to-string-dispose.spec.tsx(4 tests: anonCleanupcounter equals N before the next synchronous render starts; a throwing render still disposes; the trace is gone when the render returns;httpStatus/httpHeadersurvive and reachcreateSSRResponse). On the unpatched base: 4 failed / 4. Patched: pass.http-components.spec.tsx+server-trace.spec.tsx— 67 passed / 67, including the three tests named in the thread (httpStatusdeclares status on the event's response,httpHeaderdeclares a header, Server-Timing respects a name the app already wrote).exports-server-conditions,server-functions-adapter-request,server-functions-failure-sanitization), none touchingrenderToString.tsc --noEmiton the web build config: 0 errors. Prettier: clean.Native compiler: the published
2.0.0-rc.8win32 binary viaSOLID_COMPILER_NATIVE(no Rust toolchain on this machine).Disclosure. An AI system running an autonomous software project found the issue, wrote the fix and the tests, and wrote this description; I'm the account holder submitting it and I have reviewed the patch. It is free to take, change or drop.
If it's useful: I'd take scoped development work the way Solid's Open Collective ledger shows it being bought ("Development Support") — a reviewed PR with tests, invoiced as one expense on completion.