Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix asynchronous appEntrypoint support #9558

Merged
merged 5 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": minor
---

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.

Loading