summaryrefslogtreecommitdiff
path: root/packages/integrations/svelte
diff options
context:
space:
mode:
authorGravatar Matt Kane <m@mk.gg> 2024-09-18 16:42:44 +0100
committerGravatar Matt Kane <m@mk.gg> 2024-09-18 16:43:14 +0100
commitb0827022afa52a13d49c37c6c549212aecd32cc5 (patch)
tree41e34f22f8fa388ca78e62a2ee802367d7e3cf42 /packages/integrations/svelte
parent837ee3a4aa6b33362bd680d4a7fc786ed8639444 (diff)
parent8d4eb95086ae79339764d02215f84f4f21b96edc (diff)
downloadastro-b0827022afa52a13d49c37c6c549212aecd32cc5.tar.gz
astro-b0827022afa52a13d49c37c6c549212aecd32cc5.tar.zst
astro-b0827022afa52a13d49c37c6c549212aecd32cc5.zip
Merge branch 'main' into next
Diffstat (limited to 'packages/integrations/svelte')
-rw-r--r--packages/integrations/svelte/CHANGELOG.md6
-rw-r--r--packages/integrations/svelte/client-v5.js22
-rw-r--r--packages/integrations/svelte/client.js29
-rw-r--r--packages/integrations/svelte/package.json2
4 files changed, 41 insertions, 18 deletions
diff --git a/packages/integrations/svelte/CHANGELOG.md b/packages/integrations/svelte/CHANGELOG.md
index a498778af..528b7363c 100644
--- a/packages/integrations/svelte/CHANGELOG.md
+++ b/packages/integrations/svelte/CHANGELOG.md
@@ -7,6 +7,12 @@
- Updated dependencies [[`b6fbdaa`](https://github.com/withastro/astro/commit/b6fbdaa94a9ecec706a99e1938fbf5cd028c72e0), [`89bab1e`](https://github.com/withastro/astro/commit/89bab1e70786123fbe933a9d7a1b80c9334dcc5f), [`d74617c`](https://github.com/withastro/astro/commit/d74617cbd3278feba05909ec83db2d73d57a153e), [`e90f559`](https://github.com/withastro/astro/commit/e90f5593d23043579611452a84b9e18ad2407ef9), [`2df49a6`](https://github.com/withastro/astro/commit/2df49a6fb4f6d92fe45f7429430abe63defeacd6), [`8a53517`](https://github.com/withastro/astro/commit/8a5351737d6a14fc55f1dafad8f3b04079e81af6)]:
- astro@5.0.0-alpha.0
+## 5.7.1
+
+### Patch Changes
+
+- [#12006](https://github.com/withastro/astro/pull/12006) [`a582cb6`](https://github.com/withastro/astro/commit/a582cb61241b9c2a6f95900920145c055d5d6c12) Thanks [@johannesspohr](https://github.com/johannesspohr)! - Fix Svelte component view transition state persistence
+
## 5.7.0
### Minor Changes
diff --git a/packages/integrations/svelte/client-v5.js b/packages/integrations/svelte/client-v5.js
index fda68ee54..78bab3ea3 100644
--- a/packages/integrations/svelte/client-v5.js
+++ b/packages/integrations/svelte/client-v5.js
@@ -1,5 +1,7 @@
import { createRawSnippet, hydrate, mount, unmount } from 'svelte';
+const existingApplications = new WeakMap();
+
export default (element) => {
return async (Component, props, slotted, { client }) => {
if (!element.hasAttribute('ssr')) return;
@@ -21,15 +23,23 @@ export default (element) => {
}
const bootstrap = client !== 'only' ? hydrate : mount;
-
- const component = bootstrap(Component, {
- target: element,
- props: {
+ if (existingApplications.has(element)) {
+ existingApplications.get(element).$set({
...props,
children,
$$slots,
- },
- });
+ });
+ } else {
+ const component = bootstrap(Component, {
+ target: element,
+ props: {
+ ...props,
+ children,
+ $$slots,
+ },
+ });
+ existingApplications.set(element, component);
+ }
element.addEventListener('astro:unmount', () => unmount(component), { once: true });
};
diff --git a/packages/integrations/svelte/client.js b/packages/integrations/svelte/client.js
index 005bbe9da..288c7a661 100644
--- a/packages/integrations/svelte/client.js
+++ b/packages/integrations/svelte/client.js
@@ -3,6 +3,8 @@ const noop = () => {};
let originalConsoleWarning;
let consoleFilterRefs = 0;
+const existingApplications = new WeakMap();
+
export default (element) => {
return (Component, props, slotted, { client }) => {
if (!element.hasAttribute('ssr')) return;
@@ -14,18 +16,23 @@ export default (element) => {
try {
if (import.meta.env.DEV) useConsoleFilter();
- const component = new Component({
- target: element,
- props: {
- ...props,
- $$slots: slots,
- $$scope: { ctx: [] },
- },
- hydrate: client !== 'only',
- $$inline: true,
- });
+ if (existingApplications.has(element)) {
+ existingApplications.get(element).$set({ ...props, $$slots: slots, $$scope: { ctx: [] } });
+ } else {
+ const component = new Component({
+ target: element,
+ props: {
+ ...props,
+ $$slots: slots,
+ $$scope: { ctx: [] },
+ },
+ hydrate: client !== 'only',
+ $$inline: true,
+ });
+ existingApplications.set(element, component);
- element.addEventListener('astro:unmount', () => component.$destroy(), { once: true });
+ element.addEventListener('astro:unmount', () => component.$destroy(), { once: true });
+ }
} finally {
if (import.meta.env.DEV) finishUsingConsoleFilter();
}
diff --git a/packages/integrations/svelte/package.json b/packages/integrations/svelte/package.json
index 663309585..7241dbc6a 100644
--- a/packages/integrations/svelte/package.json
+++ b/packages/integrations/svelte/package.json
@@ -1,6 +1,6 @@
{
"name": "@astrojs/svelte",
- "version": "5.7.0",
+ "version": "5.7.1",
"description": "Use Svelte components within Astro",
"type": "module",
"types": "./dist/index.d.ts",