-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly notify page store subscribers (#13205)
fixes #13200 This PR ensures page store subscribers are correctly notified by creating a new object whenever we update the page store. I'm not sure why but when the same page object is used, it doesn't notify subscribers. There was also another bug where a popstate event would cause subscribers to get notified twice because we were calling root.$set({ page }) in addition to stores.page.notify() when updating the URL.
- Loading branch information
1 parent
9fbfb22
commit dc8ec1e
Showing
5 changed files
with
146 additions
and
20 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 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
fix: correctly notify page store subscribers |
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
47 changes: 47 additions & 0 deletions
47
packages/kit/test/apps/basics/src/routes/store/subscribe/+layout.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,47 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import { goto, pushState, replaceState, invalidate } from '$app/navigation'; | ||
import { applyAction } from '$app/forms'; | ||
let { children } = $props(); | ||
let count = $state(0); | ||
page.subscribe(() => { | ||
count += 1; | ||
}); | ||
</script> | ||
|
||
<p>{count}</p> | ||
|
||
<button | ||
onclick={() => { | ||
invalidate('/state/subscribe'); | ||
}}>invalidate</button | ||
> | ||
|
||
<button | ||
onclick={() => { | ||
replaceState(`/store/subscribe`, { active: true }); | ||
}}>replaceState</button | ||
> | ||
|
||
<button | ||
onclick={() => { | ||
pushState(`/store/subscribe`, { active: false }); | ||
}}>pushState</button | ||
> | ||
|
||
<button | ||
onclick={() => { | ||
goto(`/store/subscribe`); | ||
}}>goto</button | ||
> | ||
|
||
<button | ||
onclick={() => { | ||
applyAction({ type: 'success', status: 200 }); | ||
}}>applyAction</button | ||
> | ||
|
||
{@render children()} |
Empty file.
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