-
-
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: address bug in before/after update (#9448)
* fix: address bug in before/after update fix: address bug in before/after update * Add changeset * use every instead of filter - more explicit and enables early-exit from the loop * Update logic and comment --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
- Loading branch information
1 parent
f5101c0
commit 9eb969d
Showing
5 changed files
with
60 additions
and
3 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: corrects a beforeUpdate/afterUpdate bug |
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
7 changes: 7 additions & 0 deletions
7
packages/svelte/tests/runtime-runes/samples/runes-before-after-update/Child.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> | ||
const {count, increment} = $props(); | ||
</script> | ||
|
||
<button onclick={increment}> | ||
{count} | ||
</button> |
15 changes: 15 additions & 0 deletions
15
packages/svelte/tests/runtime-runes/samples/runes-before-after-update/_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 { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: '<button>0</button>', | ||
|
||
async test({ assert, target, component }) { | ||
const [btn] = target.querySelectorAll('button'); | ||
flushSync(() => { | ||
btn.click(); | ||
}); | ||
assert.deepEqual(component.log, ['beforeUpdate', 'afterUpdate']); | ||
assert.htmlEqual(target.innerHTML, `<button>1</button>`); | ||
} | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/svelte/tests/runtime-runes/samples/runes-before-after-update/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,22 @@ | ||
<script> | ||
import Child from './Child.svelte' | ||
import {afterUpdate, beforeUpdate} from 'svelte'; | ||
const {log = []} = $props(); | ||
let count = $state(0); | ||
const increment = () => { | ||
count++; | ||
} | ||
beforeUpdate(() => { | ||
log.push('beforeUpdate'); | ||
}); | ||
afterUpdate(() => { | ||
log.push('afterUpdate'); | ||
}); | ||
</script> | ||
|
||
<Child count={count} increment={increment} /> |
9eb969d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
svelte-5-preview – ./sites/svelte-5-preview
svelte-5-preview-svelte.vercel.app
svelte-5-preview-git-main-svelte.vercel.app
svelte-octane.vercel.app
svelte-5-preview.vercel.app