Include all client build artifacts in SSRManifest (#3678)
* Include all client build artifacts in SSRManifest * Adds a changeset
This commit is contained in:
parent
119283775a
commit
898845402c
8 changed files with 83 additions and 6 deletions
5
.changeset/unlucky-otters-agree.md
Normal file
5
.changeset/unlucky-otters-agree.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix regression with SSRManifest and client assets
|
|
@ -70,12 +70,6 @@ if(_start in adapter) {
|
|||
return void 0;
|
||||
},
|
||||
async generateBundle(_opts, bundle) {
|
||||
internals.staticFiles = new Set(
|
||||
await glob('**/*', {
|
||||
cwd: fileURLToPath(buildOpts.buildConfig.client),
|
||||
})
|
||||
);
|
||||
|
||||
// Add assets from this SSR chunk as well.
|
||||
for (const [_chunkName, chunk] of Object.entries(bundle)) {
|
||||
if (chunk.type === 'asset') {
|
||||
|
@ -101,6 +95,16 @@ export async function injectManifest(buildOpts: StaticBuildOptions, internals: B
|
|||
throw new Error(`Did not generate an entry chunk for SSR`);
|
||||
}
|
||||
|
||||
// Add assets from the client build.
|
||||
const clientStatics = new Set(
|
||||
await glob('**/*', {
|
||||
cwd: fileURLToPath(buildOpts.buildConfig.client),
|
||||
})
|
||||
);
|
||||
for(const file of clientStatics) {
|
||||
internals.staticFiles.add(file);
|
||||
}
|
||||
|
||||
const staticFiles = internals.staticFiles;
|
||||
const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
|
||||
await runHookBuildSsr({ config: buildOpts.astroConfig, manifest });
|
||||
|
|
7
packages/astro/test/fixtures/ssr-scripts/astro.config.mjs
vendored
Normal file
7
packages/astro/test/fixtures/ssr-scripts/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import preact from '@astrojs/preact';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
integrations: [preact()],
|
||||
});
|
9
packages/astro/test/fixtures/ssr-scripts/package.json
vendored
Normal file
9
packages/astro/test/fixtures/ssr-scripts/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/ssr-scripts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/preact": "workspace:",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
6
packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx
vendored
Normal file
6
packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
export default function() {
|
||||
return (
|
||||
<div>Hello world</div>
|
||||
)
|
||||
}
|
11
packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro
vendored
Normal file
11
packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
import Hello from '../components/Hello.jsx';
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
<Hello client:load />
|
||||
</body>
|
||||
</html>
|
27
packages/astro/test/ssr-scripts.test.js
Normal file
27
packages/astro/test/ssr-scripts.test.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { expect } from 'chai';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
describe('SSR Hydrated component scripts', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/ssr-scripts/',
|
||||
experimental: {
|
||||
ssr: true,
|
||||
},
|
||||
adapter: testAdapter(),
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Are included in the manifest.assets so that an adapter can know to serve static', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
|
||||
/** @type {Set<string>} */
|
||||
const assets = app.manifest.assets;
|
||||
expect(assets.size).to.be.greaterThan(0);
|
||||
});
|
||||
});
|
|
@ -1588,6 +1588,14 @@ importers:
|
|||
dependencies:
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/ssr-scripts:
|
||||
specifiers:
|
||||
'@astrojs/preact': 'workspace:'
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/preact': link:../../../../integrations/preact
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/static-build:
|
||||
specifiers:
|
||||
'@astrojs/preact': workspace:*
|
||||
|
|
Loading…
Reference in a new issue