0
Fork 0
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:
前端子鱼 2024-02-26 16:10:47 +08:00 committed by GitHub
parent 8d5ea2df5d
commit 84502b4190
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View 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

View file

@ -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 });
};
};

View file

@ -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"