summaryrefslogtreecommitdiff
path: root/packages/integrations/vue/client.js
diff options
context:
space:
mode:
authorGravatar wulinsheng123 <409187100@qq.com> 2023-04-01 01:42:03 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-31 13:42:03 -0400
commitd59e511d16482cfc7067555dd0a456098ec69e30 (patch)
tree78726248d30b6b01455db8eb3bed12a73dae9df2 /packages/integrations/vue/client.js
parent07e8a1bab4f1d1442854cec65e8f66b247fc87c7 (diff)
downloadastro-d59e511d16482cfc7067555dd0a456098ec69e30.tar.gz
astro-d59e511d16482cfc7067555dd0a456098ec69e30.tar.zst
astro-d59e511d16482cfc7067555dd0a456098ec69e30.zip
supporting top of await (#6671)
* add fix * fix * revert verison * fix fn is undefined g * add e2e test * fix unit test * delete redundant code * add changeset --------- Co-authored-by: wuls <linsheng.wu@beantechs.com>
Diffstat (limited to 'packages/integrations/vue/client.js')
-rw-r--r--packages/integrations/vue/client.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/packages/integrations/vue/client.js b/packages/integrations/vue/client.js
index 7e67825df..508cc59c0 100644
--- a/packages/integrations/vue/client.js
+++ b/packages/integrations/vue/client.js
@@ -1,4 +1,4 @@
-import { h, createSSRApp, createApp } from 'vue';
+import { h, createSSRApp, createApp, Suspense } from 'vue';
import { setup } from 'virtual:@astrojs/vue/app';
import StaticHtml from './static-html.js';
@@ -13,13 +13,26 @@ export default (element) =>
for (const [key, value] of Object.entries(slotted)) {
slots[key] = () => h(StaticHtml, { value, name: key === 'default' ? undefined : key });
}
+
+ 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)
+ }
+
if (client === 'only') {
- const app = createApp({ name, render: () => h(Component, props, slots) });
+ const app = createApp({ name, render: () => content });
await setup(app);
app.mount(element, false);
} else {
- const app = createSSRApp({ name, render: () => h(Component, props, slots) });
+ const app = createSSRApp({ name, render: () => content });
await setup(app);
app.mount(element, true);
}
};
+
+function isAsync (fn) {
+ const constructor = fn?.constructor
+ return constructor && constructor.name === 'AsyncFunction';
+}