fix: flush pending changes after rendering `failed` snippet (#16995)

fixes #16730
pull/16200/merge
Simon H 4 days ago committed by GitHub
parent cd3a11edff
commit bd697c12c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: flush pending changes after rendering `failed` snippet

@ -30,7 +30,6 @@ import {
skip_nodes, skip_nodes,
set_hydrate_node set_hydrate_node
} from '../hydration.js'; } from '../hydration.js';
import { get_next_sibling } from '../operations.js';
import { queue_micro_task } from '../task.js'; import { queue_micro_task } from '../task.js';
import * as e from '../../errors.js'; import * as e from '../../errors.js';
import * as w from '../../warnings.js'; import * as w from '../../warnings.js';
@ -402,6 +401,7 @@ export class Boundary {
if (failed) { if (failed) {
queue_micro_task(() => { queue_micro_task(() => {
this.#failed_effect = this.#run(() => { this.#failed_effect = this.#run(() => {
Batch.ensure();
this.#is_creating_fallback = true; this.#is_creating_fallback = true;
try { try {

@ -0,0 +1,12 @@
import { tick } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const btn = target.querySelector('button');
btn?.click();
await tick();
assert.deepEqual(logs, ['attachment']);
}
});

@ -0,0 +1,20 @@
<script>
let fail = $state(false);
function error() {
throw new Error('oops');
}
function attachment() {
console.log('attachment');
}
</script>
<svelte:boundary>
{fail ? error() : 'all good'}
<button onclick={() => fail = true}>fail</button>
{#snippet failed()}
<div {@attach attachment}>oops!</div>
{/snippet}
</svelte:boundary>
Loading…
Cancel
Save