Skip to content

Commit f8283fb

Browse files
authored
fix: remove let variable from select binding dependencies (#8969)
Fixes #2943 The issue linked above invalidates a variable that is not defined in <script> but instead is defined as a let: variable, which does not make sense to invalidate, therefore, this PR exists.
1 parent cb1358c commit f8283fb

File tree

8 files changed

+97
-1
lines changed

8 files changed

+97
-1
lines changed

.changeset/cyan-geese-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: remove `let:variable` slot bindings from select binding dependencies

packages/svelte/src/compiler/compile/render_dom/wrappers/Element/Attribute.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
9191
if (select && select.select_binding_dependencies) {
9292
select.select_binding_dependencies.forEach((prop) => {
9393
this.node.dependencies.forEach((dependency) => {
94-
this.parent.renderer.component.indirect_dependencies.get(prop).add(dependency);
94+
if (this.node.scope.is_top_level(dependency)) {
95+
this.parent.renderer.component.indirect_dependencies.get(prop).add(dependency);
96+
}
9597
});
9698
});
9799
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
const tasks = ["do laundry", "do taxes", "cook food", "watch the kids"];
3+
</script>
4+
5+
<slot {tasks} />
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export default {
2+
html: `
3+
<select>
4+
<option value='do laundry'>do laundry</option>
5+
<option value='do taxes'>do taxes</option>
6+
<option value='cook food'>cook food</option>
7+
<option value='watch the kids'>watch the kids</option>
8+
</select>
9+
<p>1</p>
10+
`,
11+
12+
async test({ assert, component, target, window }) {
13+
const select = target.querySelector('select');
14+
const options = target.querySelectorAll('option');
15+
16+
assert.equal(component.tasks_touched, 1);
17+
18+
const change = new window.Event('change');
19+
options[1].selected = true;
20+
await select.dispatchEvent(change);
21+
22+
assert.equal(component.selected, options[1].value);
23+
assert.equal(component.tasks_touched, 1);
24+
}
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
import Parent from "./Parent.svelte";
3+
export let selected;
4+
export let tasks = ['do nothing'];
5+
export let tasks_touched = 0;
6+
7+
$: {
8+
tasks, tasks_touched++;
9+
}
10+
</script>
11+
12+
<Parent let:tasks={tasks}>
13+
<select bind:value={selected}>
14+
{#each tasks as task}
15+
<option value={task}>{task}</option>
16+
{/each}
17+
</select>
18+
</Parent>
19+
<p>{tasks_touched}</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
const tasks = ["do laundry", "do taxes", "cook food", "watch the kids"];
3+
</script>
4+
5+
<slot {tasks} />
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
html: `
3+
<select>
4+
<option value='do laundry'>do laundry</option>
5+
<option value='do taxes'>do taxes</option>
6+
<option value='cook food'>cook food</option>
7+
<option value='watch the kids'>watch the kids</option>
8+
</select>
9+
`,
10+
11+
async test({ assert, component, target, window }) {
12+
const select = target.querySelector('select');
13+
const options = target.querySelectorAll('option');
14+
15+
const change = new window.Event('change');
16+
options[1].selected = true;
17+
await select.dispatchEvent(change);
18+
19+
assert.equal(component.selected, options[1].value);
20+
}
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Parent from "./Parent.svelte";
3+
export let selected;
4+
</script>
5+
6+
<Parent let:tasks={tasks}>
7+
<select bind:value={selected}>
8+
{#each tasks as task}
9+
<option value={task}>{task}</option>
10+
{/each}
11+
</select>
12+
</Parent>

0 commit comments

Comments
 (0)