Skip to content

Commit

Permalink
fix: svelte 5 mount/hydrate api change. (#10224)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwc authored Feb 26, 2024
1 parent 8d5ea2d commit 84502b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-jobs-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/svelte": minor
---

Bumps Svelte 5 peer dependency to `^5.0.0-next.56` and support its latest breaking changes
10 changes: 6 additions & 4 deletions packages/integrations/svelte/client-v5.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -28,7 +30,7 @@ export default (element) => {
},
});

element.addEventListener('astro:unmount', () => destroy(), { once: true });
element.addEventListener('astro:unmount', () => unmount(component), { once: true });
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 84502b4

Please sign in to comment.