[fix] handle promise rejections for {#await} in SSR (#6790)

pull/6796/head
Conduitry 4 years ago committed by GitHub
parent e82cf3f6d7
commit 10ce5c95fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@ jobs:
timeout-minutes: 15 timeout-minutes: 15
strategy: strategy:
matrix: matrix:
node-version: [8, 10, 12, 14] node-version: [8, 10, 12, 14, 16]
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1

@ -13,7 +13,10 @@ export default function(node: AwaitBlock, renderer: Renderer, options: RenderOpt
renderer.add_expression(x` renderer.add_expression(x`
function(__value) { function(__value) {
if (@is_promise(__value)) return ${pending}; if (@is_promise(__value)) {
__value.then(null, @noop);
return ${pending};
}
return (function(${node.then_node ? node.then_node : ''}) { return ${then}; }(__value)); return (function(${node.then_node ? node.then_node : ''}) { return ${then}; }(__value));
}(${node.expression.node}) }(${node.expression.node})
`); `);

@ -52,6 +52,7 @@ describe('hydration', () => {
const cwd = path.resolve(`${__dirname}/samples/${dir}`); const cwd = path.resolve(`${__dirname}/samples/${dir}`);
compileOptions = config.compileOptions || {}; compileOptions = config.compileOptions || {};
compileOptions.accessors = 'accessors' in config ? config.accessors : true;
const window = env(); const window = env();

@ -1,9 +1,9 @@
<script> <script>
let clicked; export let clicked;
</script> </script>
<button on:click='{() => clicked = true}'>click me</button> <button on:click='{() => clicked = true}'>click me</button>
{#if clicked} {#if clicked}
<p>clicked!</p> <p>clicked!</p>
{/if} {/if}

@ -25,12 +25,13 @@ let compile = null;
const sveltePath = process.cwd().split('\\').join('/'); const sveltePath = process.cwd().split('\\').join('/');
let unhandled_rejection = false; let unhandled_rejection = false;
process.on('unhandledRejection', err => { function unhandledRejection_handler(err) {
unhandled_rejection = err; unhandled_rejection = err;
}); }
describe('runtime', () => { describe('runtime', () => {
before(() => { before(() => {
process.on('unhandledRejection', unhandledRejection_handler);
svelte = loadSvelte(false); svelte = loadSvelte(false);
svelte$ = loadSvelte(true); svelte$ = loadSvelte(true);
@ -46,6 +47,7 @@ describe('runtime', () => {
return setupHtmlEqual(); return setupHtmlEqual();
}); });
after(() => process.removeListener('unhandledRejection', unhandledRejection_handler));
const failed = new Set(); const failed = new Set();

Loading…
Cancel
Save