Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
Rich-Harris committed May 20, 2025
commit 4e3bd9489732187be222efd9d5abf0f08e8b09bb
14 changes: 8 additions & 6 deletions packages/svelte/src/internal/client/dom/elements/attachments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @import { Effect } from '#client' */
import { block, branch, destroy_effect } from '../../reactivity/effects.js';
import { block, branch, effect, destroy_effect } from '../../reactivity/effects.js';

// TODO in 6.0 or 7.0, when we remove legacy mode, we can simplify this by
// getting rid of the block/branch stuff and just letting the effect rip.
Expand All @@ -14,17 +14,19 @@ export function attach(node, get_fn) {
var fn = undefined;

/** @type {Effect | null} */
var effect;
var e;

block(() => {
if (fn !== (fn = get_fn())) {
if (effect) {
destroy_effect(effect);
effect = null;
if (e) {
destroy_effect(e);
e = null;
}

if (fn) {
effect = branch(() => /** @type {(node: Element) => void} */ (fn)(node));
e = branch(() => {
effect(() => /** @type {(node: Element) => void} */ (fn)(node));
});
}
}
});
Expand Down