Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{#await} in SSR should suppress rejecting promises #6789

Closed
Conduitry opened this issue Sep 29, 2021 · 1 comment · Fixed by #6790
Closed

{#await} in SSR should suppress rejecting promises #6789

Conduitry opened this issue Sep 29, 2021 · 1 comment · Fixed by #6790
Labels

Comments

@Conduitry
Copy link
Member

Describe the bug

(This came out of sveltejs/kit#2520 but is a separate matter from how SvelteKit ought to deal with user code that creates unhandled rejected promises.)

Node 16 terminates the process immediately when it detects that a dangling promise has rejected and no callbacks have been attached to handle that. SSR code for an {#await} block ignores the promise resolution (and just renders the waiting-for-promise content), which means that Node thinks the promise has not been handled appropriately. In Node 14, this results in a noisy warning, and in Node 16 this results in the program ending with an error.

Since we specifically do not care about the promise resolution/rejection in SSR in {#await}s (and since there's nothing we can do about this while SSR itself is synchronous), the generated SSR code for an {#await} block should contain explicit (dummy) handlers for the promise, to appease Node.

Reproduction

{#await Promise.reject('foo')}
	bar
{/await}

Compiling this in SSR mode and running it in Node 16 results in the process crashing, because you are generating a promise that rejects but it is then never handled.

Logs

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "foo".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

System Info

Node: 16.10.0

Severity

annoyance

@Conduitry
Copy link
Member Author

In 3.43.1, passing a rejecting promise to an {#await} no longer crashes the process in Node 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant