Skip to content

renderToPipeableStream: Expose errors through onError, no longer emit un-catchable error event on internal stream#405

Merged
JoviDeCroock merged 1 commit intopreactjs:mainfrom
f0x52:streaming-errors
Jan 12, 2025
Merged

renderToPipeableStream: Expose errors through onError, no longer emit un-catchable error event on internal stream#405
JoviDeCroock merged 1 commit intopreactjs:mainfrom
f0x52:streaming-errors

Conversation

@f0x52
Copy link
Contributor

@f0x52 f0x52 commented Jan 4, 2025

Fixes #404

Changes error and abort handling in renderToPipeableStream so the stream no longer emits an uncatchable error event. Instead errors are passed to options.onError if provided. If there is no error callback it's rethrown, though maybe that's not ideal since it happens in the async chain, so can't really be caught either. Alternatively this could just console.error, so it doesn't get silently swallowed entirely?

Also added an optional reason argument for stream.abort(), defaulting to new Error(The render was aborted by the server without a reason.) inspired by React. Previously this was just new Error('aborted'), though this was never exposed to consumers.
Abort still destroys the stream, and also calls the onError callback (if defined) with the reason

… un-catchable error event on internal stream
@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2025

🦋 Changeset detected

Latest commit: 310e1bb

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

This PR includes changesets to release 1 package
Name Type
preact-render-to-string 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

@JoviDeCroock JoviDeCroock merged commit 0a698f6 into preactjs:main Jan 12, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request Jan 12, 2025
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.

Errors in renderToPipeableStream crash Node.js process

2 participants