Skip to content

Commit 46950e8

Browse files
committed
fix: ensure custom element attribute/prop changes are in their own context
1 parent 4441952 commit 46950e8

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

.changeset/wild-parents-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure custom element attribute/prop changes are in their own context

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import * as w from '../../warnings.js';
77
import { LOADING_ATTR_SYMBOL } from '../../constants.js';
88
import { queue_idle_task, queue_micro_task } from '../task.js';
99
import { is_capture_event, is_delegated, normalize_attribute } from '../../../../utils.js';
10+
import {
11+
active_effect,
12+
active_reaction,
13+
set_active_effect,
14+
set_active_reaction
15+
} from '../../runtime.js';
1016

1117
/**
1218
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
@@ -145,10 +151,24 @@ export function set_xlink_attribute(dom, attribute, value) {
145151
* @param {any} value
146152
*/
147153
export function set_custom_element_data(node, prop, value) {
148-
if (get_setters(node).includes(prop)) {
149-
node[prop] = value;
150-
} else {
151-
set_attribute(node, prop, value);
154+
// We need to ensure that setting custom element props, which can
155+
// invoke lifecycle methods on other custom elements, does not also
156+
// associate those lifecycle methods with the current active reaction
157+
// or effect
158+
var previous_reaction = active_reaction;
159+
var previous_effect = active_effect;
160+
161+
set_active_reaction(null);
162+
set_active_effect(null);
163+
try {
164+
if (get_setters(node).includes(prop)) {
165+
node[prop] = value;
166+
} else {
167+
set_attribute(node, prop, value);
168+
}
169+
} finally {
170+
set_active_reaction(previous_reaction);
171+
set_active_effect(previous_effect);
152172
}
153173
}
154174

0 commit comments

Comments
 (0)