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:
parent
22f42d11a4
commit
e496b2e3b8
11 changed files with 101 additions and 2 deletions
5
.changeset/ninety-buses-occur.md
Normal file
5
.changeset/ninety-buses-occur.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/vue": patch
|
||||
---
|
||||
|
||||
Fixes support for async `appEntrypoint`
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
14
packages/integrations/vue/test/fixtures/app-entrypoint-async/astro.config.mjs
vendored
Normal file
14
packages/integrations/vue/test/fixtures/app-entrypoint-async/astro.config.mjs
vendored
Normal 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(),
|
||||
],
|
||||
},
|
||||
})
|
10
packages/integrations/vue/test/fixtures/app-entrypoint-async/package.json
vendored
Normal file
10
packages/integrations/vue/test/fixtures/app-entrypoint-async/package.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
3
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Bar.vue
vendored
Normal file
3
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Bar.vue
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<template>
|
||||
<div id="bar">works</div>
|
||||
</template>
|
3
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Baz.vue
vendored
Normal file
3
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Baz.vue
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<template>
|
||||
<div id="baz">works</div>
|
||||
</template>
|
6
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Foo.vue
vendored
Normal file
6
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/components/Foo.vue
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
<template>
|
||||
<div id="foo">
|
||||
<Bar />
|
||||
<Baz />
|
||||
</div>
|
||||
</template>
|
11
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/pages/_app.ts
vendored
Normal file
11
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/pages/_app.ts
vendored
Normal 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);
|
||||
}
|
12
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/pages/index.astro
vendored
Normal file
12
packages/integrations/vue/test/fixtures/app-entrypoint-async/src/pages/index.astro
vendored
Normal 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
12
pnpm-lock.yaml
generated
|
@ -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':
|
||||
|
|
Loading…
Add table
Reference in a new issue