Skip to content

Commit

Permalink
Fix asynchronous appEntrypoint support (#9558)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhthomas authored Jan 1, 2024
1 parent 22f42d1 commit e496b2e
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-buses-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/vue": patch
---

Fixes support for async `appEntrypoint`
4 changes: 2 additions & 2 deletions packages/integrations/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function virtualAppEntrypoint(options?: Options): Plugin {
return `\
import * as mod from ${JSON.stringify(appEntrypoint)};
export const setup = (app) => {
export const setup = async (app) => {
if ('default' in mod) {
mod.default(app);
await mod.default(app);
} else {
${
!isBuild
Expand Down
23 changes: 23 additions & 0 deletions packages/integrations/vue/test/app-entrypoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,26 @@ describe('App Entrypoint /src/absolute', () => {
expect(js).not.to.match(/\w+\.component\(\"Bar\"/gm);
});
});

describe('App Entrypoint async', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/app-entrypoint-async/',
});
await fixture.build();
});

it('loads during SSR', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerioLoad(html);

// test 1: component before await renders
expect($('#foo > #bar').text()).to.eq('works');

// test 2: component after await renders
expect($('#foo > #baz').text()).to.eq('works');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'astro/config';
import vue from '@astrojs/vue';
import ViteSvgLoader from 'vite-svg-loader'

export default defineConfig({
integrations: [vue({
appEntrypoint: '/src/pages/_app'
})],
vite: {
plugins: [
ViteSvgLoader(),
],
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@test/vue-app-entrypoint-async",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vue": "workspace:*",
"astro": "workspace:*",
"vite-svg-loader": "5.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div id="bar">works</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div id="baz">works</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div id="foo">
<Bar />
<Baz />
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { App } from 'vue'
import Bar from '../components/Bar.vue'
import Baz from '../components/Baz.vue'

export default async function setup(app: App) {
app.component('Bar', Bar);

await new Promise(resolve => setTimeout(resolve, 250));

app.component('Baz', Baz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
import Foo from '../components/Foo.vue';
---

<html>
<head>
<title>Vue App Entrypoint</title>
</head>
<body>
<Foo client:load />
</body>
</html>
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e496b2e

Please sign in to comment.