From f31c8d44ee33b053e837bfc8961c4fc7ccef890c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=AD=90=E9=B1=BC?= Date: Sat, 24 Feb 2024 09:04:14 +0800 Subject: [PATCH 1/3] fix: svelte 5 mount/hydrate api change. --- .changeset/smart-jobs-care.md | 5 +++++ packages/integrations/svelte/client-v5.js | 10 ++++++---- packages/integrations/svelte/package.json | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changeset/smart-jobs-care.md diff --git a/.changeset/smart-jobs-care.md b/.changeset/smart-jobs-care.md new file mode 100644 index 000000000000..de6b4c68fd3e --- /dev/null +++ b/.changeset/smart-jobs-care.md @@ -0,0 +1,5 @@ +--- +"@astrojs/svelte": patch +--- + +fix: svelte 5 mount/hydrate api change. diff --git a/packages/integrations/svelte/client-v5.js b/packages/integrations/svelte/client-v5.js index eaa06974c242..819363d5e0f1 100644 --- a/packages/integrations/svelte/client-v5.js +++ b/packages/integrations/svelte/client-v5.js @@ -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 }); }; }; diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index 28d78bf29422..c931261980bd 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -48,12 +48,12 @@ "devDependencies": { "astro": "workspace:*", "astro-scripts": "workspace:*", - "svelte": "^4.2.5", + "svelte": "^4.2.12", "vite": "^5.1.2" }, "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" From e9c34a971f5b13909a49009cbedcd136b6c412bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=AD=90=E9=B1=BC?= Date: Sat, 24 Feb 2024 09:18:26 +0800 Subject: [PATCH 2/3] fix: svelte 5 mount/hydrate api change. --- packages/integrations/svelte/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json index c931261980bd..1976f8fa6bee 100644 --- a/packages/integrations/svelte/package.json +++ b/packages/integrations/svelte/package.json @@ -48,7 +48,7 @@ "devDependencies": { "astro": "workspace:*", "astro-scripts": "workspace:*", - "svelte": "^4.2.12", + "svelte": "^4.2.5", "vite": "^5.1.2" }, "peerDependencies": { From 5e054c4efa2f0fed3da1a16d66c890fcf89562de Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 26 Feb 2024 16:07:22 +0800 Subject: [PATCH 3/3] Update .changeset/smart-jobs-care.md --- .changeset/smart-jobs-care.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/smart-jobs-care.md b/.changeset/smart-jobs-care.md index de6b4c68fd3e..d0da72ac6ebc 100644 --- a/.changeset/smart-jobs-care.md +++ b/.changeset/smart-jobs-care.md @@ -1,5 +1,5 @@ --- -"@astrojs/svelte": patch +"@astrojs/svelte": minor --- -fix: svelte 5 mount/hydrate api change. +Bumps Svelte 5 peer dependency to `^5.0.0-next.56` and support its latest breaking changes