summaryrefslogtreecommitdiff
path: root/packages/integrations/vue
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/vue
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/vue')
-rw-r--r--packages/integrations/vue/CHANGELOG.md6
-rw-r--r--packages/integrations/vue/client.js46
-rw-r--r--packages/integrations/vue/package.json2
3 files changed, 39 insertions, 15 deletions
diff --git a/packages/integrations/vue/CHANGELOG.md b/packages/integrations/vue/CHANGELOG.md
index 88ff9204e..a6fbc1ca6 100644
--- a/packages/integrations/vue/CHANGELOG.md
+++ b/packages/integrations/vue/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
+## 4.5.1
+
+### Patch Changes
+
+- [#11946](https://github.com/withastro/astro/pull/11946) [`b75bfc8`](https://github.com/withastro/astro/commit/b75bfc8cc41f5c631c10055b78670fdc26dff23a) Thanks [@johannesspohr](https://github.com/johannesspohr)! - Fix vue islands keeping their state when using view transition persistence
+
## 4.5.0
### Minor Changes
diff --git a/packages/integrations/vue/client.js b/packages/integrations/vue/client.js
index 807f843fc..58ee11d5c 100644
--- a/packages/integrations/vue/client.js
+++ b/packages/integrations/vue/client.js
@@ -2,6 +2,9 @@ import { setup } from 'virtual:@astrojs/vue/app';
import { Suspense, createApp, createSSRApp, h } from 'vue';
import StaticHtml from './static-html.js';
+// keep track of already initialized apps, so we don't hydrate again for view transitions
+let appMap = new WeakMap();
+
export default (element) =>
async (Component, props, slotted, { client }) => {
if (!element.hasAttribute('ssr')) return;
@@ -15,21 +18,36 @@ export default (element) =>
const isHydrate = client !== 'only';
const bootstrap = isHydrate ? createSSRApp : createApp;
- const app = bootstrap({
- name,
- render() {
- let content = h(Component, props, slots);
- // related to https://github.com/withastro/astro/issues/6549
- // if the component is async, wrap it in a Suspense component
- if (isAsync(Component.setup)) {
- content = h(Suspense, null, content);
- }
- return content;
- },
- });
- await setup(app);
- app.mount(element, isHydrate);
+ // keep a reference to the app, props and slots so we can update a running instance later
+ let appInstance = appMap.get(element);
+
+ if (!appInstance) {
+ appInstance = {
+ props,
+ slots,
+ };
+ const app = bootstrap({
+ name,
+ render() {
+ let content = h(Component, appInstance.props, appInstance.slots);
+ appInstance.component = this;
+ // related to https://github.com/withastro/astro/issues/6549
+ // if the component is async, wrap it in a Suspense component
+ if (isAsync(Component.setup)) {
+ content = h(Suspense, null, content);
+ }
+ return content;
+ },
+ });
+ await setup(app);
+ app.mount(element, isHydrate);
+ appMap.set(element, appInstance);
+ } else {
+ appInstance.props = props;
+ appInstance.slots = slots;
+ appInstance.component.$forceUpdate();
+ }
element.addEventListener('astro:unmount', () => app.unmount(), { once: true });
};
diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json
index c11771173..eb723f8fb 100644
--- a/packages/integrations/vue/package.json
+++ b/packages/integrations/vue/package.json
@@ -1,6 +1,6 @@
{
"name": "@astrojs/vue",
- "version": "4.5.0",
+ "version": "4.5.1",
"description": "Use Vue components within Astro",
"type": "module",
"types": "./dist/index.d.ts",