Skip to content

fix: resolve ReadableStream locked error during build with defer()#64

Merged
uhyo merged 1 commit intomasterfrom
fix/readablestream-locked-during-build
Feb 19, 2026
Merged

fix: resolve ReadableStream locked error during build with defer()#64
uhyo merged 1 commit intomasterfrom
fix/readablestream-locked-during-build

Conversation

@uhyo
Copy link
Owner

@uhyo uhyo commented Feb 19, 2026

Summary

  • During vite build, DeferredComponent rendered in SSR calls registry.load(), which locks stream1 (from stream.tee()) via createFromReadableStream. Later, loadAll() attempted to drain the same locked stream, causing ERR_INVALID_STATE: ReadableStream is locked.
  • Fixed by storing a drainPromise (from draining stream2 of the tee) on each DeferEntry, and having loadAll() await these promises instead of attempting to drain the potentially-locked stream1.
  • Also simplified loadAll() by removing the per-state switch in favor of uniformly awaiting drain promises.

Test plan

  • pnpm build succeeds (including docs and example packages that use defer())
  • All 19 e2e tests pass (pnpm test:e2e), including SSR defer tests
  • Verify the fix against the reproducing project (funstack-router docs)

🤖 Generated with Claude Code

During vite build, DeferredComponent in SSR calls registry.load() which
locks stream1 via createFromReadableStream. Later, loadAll() tried to
drain the same locked stream, causing ERR_INVALID_STATE.

Fix by storing a drainPromise (from draining stream2 of the tee) on
each DeferEntry, and having loadAll() await these promises instead of
attempting to drain the potentially-locked stream1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@uhyo uhyo merged commit 377066b into master Feb 19, 2026
1 check passed
@uhyo uhyo deleted the fix/readablestream-locked-during-build branch February 19, 2026 12:45
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.

1 participant

Comments