Include all client build artifacts in SSRManifest (#3678)

* Include all client build artifacts in SSRManifest

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-06-22 11:35:54 -04:00 committed by GitHub
parent 119283775a
commit 898845402c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix regression with SSRManifest and client assets

View file

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

View file

@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import preact from '@astrojs/preact';
// https://astro.build/config
export default defineConfig({
integrations: [preact()],
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/ssr-scripts",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/preact": "workspace:",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,6 @@
export default function() {
return (
<div>Hello world</div>
)
}

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

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

View file

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