feat(core): defer AsyncSignal errors during render#8757
Open
wmertens wants to merge 2 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: c40e4b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
@qwik.dev/core
@qwik.dev/router
eslint-plugin-qwik
create-qwik
@qwik.dev/optimizer
commit: |
Contributor
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Varixo
reviewed
Jun 21, 2026
maiieul
reviewed
Jun 21, 2026
| Read `.value` when you need the result. If the result is not ready yet, that part of the UI can wait and a [`<Suspense>`](/docs/labs/suspense/index.mdx) boundary can show fallback UI. | ||
|
|
||
| Note: If the function errored, reading from `.value` will throw the error. This is intentional, so you can handle errors with a `<ErrorBoundary>`. To avoid this, check `.error` before reading `.value`. | ||
|
|
ecba0a3 to
c477a6b
Compare
There was a problem hiding this comment.
Pull request overview
This PR changes AsyncSignal error semantics during component rendering so that reading an errored async signal’s .value can be deferred until after render, allowing patterns like {signal.value && ...} and {signal.error && ...} without .value throwing mid-render.
Changes:
- Add render-only error deferral tracking to the invoke context and enable it during
executeComponent(). - Defer
AsyncSignalImpl.untrackedValuethrowing during a render and rethrow after render if.errorwas not read. - Update API/runtime docs and add a regression test for the “read
.valuethen.error” render pattern, plus a changeset.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/qwik/src/core/use/use-core.ts | Adds per-render context field to track deferred async-signal errors. |
| packages/qwik/src/core/shared/component-execution.ts | Enables/reset tracking during component execution and rethrows unread async-signal errors post-render. |
| packages/qwik/src/core/reactive-primitives/impl/async-signal-impl.ts | Defers throwing from .value during render and marks .error reads as handled. |
| packages/qwik/src/core/reactive-primitives/signal.public.ts | Documents the new render-only deferred-throw behavior for AsyncSignal. |
| packages/qwik/src/core/tests/use-async.spec.tsx | Adds a test ensuring separate .value/.error reads in render don’t throw. |
| packages/docs/src/routes/docs/(qwik)/core/state/index.mdx | Updates state docs around useAsync$() error behavior. |
| packages/docs/src/routes/api/qwik/index.mdx | Updates API docs text for AsyncSignal to mention render deferral. |
| packages/docs/src/routes/api/qwik/api.json | Regenerates API docs JSON content to include the updated AsyncSignal docs. |
| .changeset/async-signal-defer-error-read.md | Declares a minor release for the new AsyncSignal render behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| Read `.value` when you need the result. If the result is not ready yet, that part of the UI can wait and a [`<Suspense>`](/docs/labs/suspense/index.mdx) boundary can show fallback UI. | ||
|
|
||
| Note: If the function errored, reading from `.value` will throw the error. This is intentional, so you can handle errors with a `<ErrorBoundary>`. To avoid this, check `.error` before reading `.value`. |
Comment on lines
+369
to
388
| it('does not throw when .value and .error are read separately in a render', async () => { | ||
| const Counter = component$(() => { | ||
| const doubleCount = useAsync$(() => Promise.reject(new Error('boom'))); | ||
| // Reading .value first must not throw, because the render also handles .error. | ||
| const value = doubleCount.value; | ||
| const error = doubleCount.error; | ||
| return <div>{error ? `error: ${error.message}` : value}</div>; | ||
| }); | ||
| let threw = false; | ||
| let container; | ||
| try { | ||
| ({ container } = await render(<Counter />, { debug })); | ||
| } catch { | ||
| threw = true; | ||
| } | ||
| // Reading .value of the errored signal did not throw, because .error was also read. | ||
| expect(threw).toBe(false); | ||
| expect(container!.element.querySelector('div')?.textContent).toBe('error: boom'); | ||
| }); | ||
| }); |
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.
this allows writing
Note that setting error does not clear .value so the stale value can still be shown.