mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix: svelte 5 mount/hydrate api change. (#10224)
This commit is contained in:
parent
8d5ea2df5d
commit
84502b4190
3 changed files with 12 additions and 5 deletions
5
.changeset/smart-jobs-care.md
Normal file
5
.changeset/smart-jobs-care.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/svelte": minor
|
||||
---
|
||||
|
||||
Bumps Svelte 5 peer dependency to `^5.0.0-next.56` and support its latest breaking changes
|
|
@ -1,11 +1,11 @@
|
|||
import { mount } from 'svelte';
|
||||
import { hydrate, mount, unmount } from 'svelte';
|
||||
import { add_snippet_symbol } from 'svelte/internal';
|
||||
|
||||
// Allow a slot to be rendered as a snippet (dev validation only)
|
||||
const tagSlotAsSnippet = import.meta.env.DEV ? add_snippet_symbol : (s) => s;
|
||||
|
||||
export default (element) => {
|
||||
return async (Component, props, slotted) => {
|
||||
return async (Component, props, slotted, { client }) => {
|
||||
if (!element.hasAttribute('ssr')) return;
|
||||
|
||||
let children = undefined;
|
||||
|
@ -19,7 +19,9 @@ export default (element) => {
|
|||
}
|
||||
}
|
||||
|
||||
const [, destroy] = mount(Component, {
|
||||
const bootstrap = client !== 'only' ? hydrate : mount;
|
||||
|
||||
const component = bootstrap(Component, {
|
||||
target: element,
|
||||
props: {
|
||||
...props,
|
||||
|
@ -28,7 +30,7 @@ export default (element) => {
|
|||
},
|
||||
});
|
||||
|
||||
element.addEventListener('astro:unmount', () => destroy(), { once: true });
|
||||
element.addEventListener('astro:unmount', () => unmount(component), { once: true });
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
},
|
||||
"peerDependencies": {
|
||||
"astro": "^4.0.0",
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.1"
|
||||
"svelte": "^4.0.0 || ^5.0.0-next.56"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.14.1"
|
||||
|
|
Loading…
Reference in a new issue