fix: handle renderer.run rejections (#17591)

* fix: handle renderer run rejections

* add test

* changeset

* simplify

* explanatory comment

---------

Co-authored-by: Antonio Bennett <abennett@mabelslabels.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>
fix-15339
Antonio Bennett 6 days ago committed by 7nik
parent 2339a739ec
commit 16ea0cee92

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent unhandled exceptions arising from dangling promises in <script>

@ -11,6 +11,7 @@ import { attributes } from './index.js';
import { get_render_context, with_render_context, init_render_context } from './render-context.js';
import { sha256 } from './crypto.js';
import * as devalue from 'devalue';
import { noop } from '../shared/utils.js';
/** @typedef {'head' | 'body'} RendererType */
/** @typedef {{ [key in RendererType]: string }} AccumulatedContent */
@ -162,6 +163,11 @@ export class Renderer {
promises.push(promise);
}
// prevent unhandled rejections, and attach the promise to the renderer instance
// so that rejections correctly cause rendering to fail
promise.catch(noop);
this.promise = promise;
return promises;
}

@ -0,0 +1,6 @@
import { test } from '../../test';
export default test({
mode: ['async-server', 'hydrate'],
error: 'oops'
});

@ -0,0 +1,7 @@
<script>
await 1;
throw new Error('oops');
</script>
<h1>hello</h1>
Loading…
Cancel
Save