Skip to content

fix: skip effects inside dynamic component that is about to be destroyed #16601

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

Merged
merged 2 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-files-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: skip effects inside dynamic component that is about to be destroyed
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export function component(node, get_component, render_fn) {
if (defer) {
offscreen_fragment = document.createDocumentFragment();
offscreen_fragment.append((target = create_text()));
if (effect) {
/** @type {Batch} */ (current_batch).skipped_effects.add(effect);
}
}

pending_effect = branch(() => render_fn(target, component));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let { data } = $props();
</script>

{#each data.obj.arr as i}
<p>{i}</p>
{/each}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Comp 2</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
async test({ assert, target }) {
const [btn] = target.querySelectorAll('button');
btn.click();
flushSync();
assert.htmlEqual(target.innerHTML, `<button>Change</button> <p>Comp 2</p>`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
import Comp_1 from './Comp-1.svelte';
import Comp_2 from './Comp-2.svelte';

let Comp = $state.raw(Comp_1);
let data = $state.raw({ obj: { arr: [1, 2, 3] } });

function change() {
Comp = Comp_2;
data = {};
}
</script>

<button onclick={change}>Change</button>

<Comp {data} />
Loading