-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure spread events are always added
In edge cases it may happen that set_attributes is re-run before the effect is executed. In that case the render effect which initiates this re-run will destroy the inner effect and it will never run. But because next and prev may have the same keys, the event would not get added again and it would get lost. We prevent this by using a root effect. The added test case doesn't fail for some reason without this fix, but it does fail when you test it out manually, so I still added it. Found through #10359 (comment)
- Loading branch information
1 parent
59f4feb
commit 45b83a7
Showing
4 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte": patch | ||
--- | ||
|
||
fix: ensure spread events are added even when rerunning spread immediately |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/svelte/tests/runtime-runes/samples/event-spread-rerun/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { test, ok } from '../../test'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
|
||
async test({ assert, logs, target }) { | ||
const input = target.querySelector('input'); | ||
ok(input); | ||
|
||
input.value = 'foo'; | ||
await input.dispatchEvent(new Event('input')); | ||
|
||
assert.deepEqual(logs, ['hi']); | ||
} | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/svelte/tests/runtime-runes/samples/event-spread-rerun/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let rest = $state(undefined); | ||
</script> | ||
|
||
<input {...rest} oninput={() => console.log('hi')}> | ||
<!-- after input and inside template so that attribute spread reruns immediately --> | ||
{!rest ? (rest = {}) : false} |