0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-31 23:31:30 -05:00

Fix asynchronous appEntrypoint support (#9558)

This commit is contained in:
Michael Thomas 2024-01-01 02:44:17 -05:00 committed by GitHub
parent 22f42d11a4
commit e496b2e3b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 101 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/vue": patch
---
Fixes support for async `appEntrypoint`

View file

@ -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

View file

@ -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');
});
});

View file

@ -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(),
],
},
})

View file

@ -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"
}
}

View file

@ -0,0 +1,3 @@
<template>
<div id="bar">works</div>
</template>

View file

@ -0,0 +1,3 @@
<template>
<div id="baz">works</div>
</template>

View file

@ -0,0 +1,6 @@
<template>
<div id="foo">
<Bar />
<Baz />
</div>
</template>

View file

@ -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);
}

View file

@ -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
pnpm-lock.yaml generated
View file

@ -4861,6 +4861,18 @@ importers:
specifier: 5.0.1
version: 5.0.1
packages/integrations/vue/test/fixtures/app-entrypoint-async:
dependencies:
'@astrojs/vue':
specifier: workspace:*
version: link:../../..
astro:
specifier: workspace:*
version: link:../../../../../astro
vite-svg-loader:
specifier: 5.0.1
version: 5.0.1
packages/integrations/vue/test/fixtures/app-entrypoint-no-export-default:
dependencies:
'@astrojs/vue':