Skip to content

Commit

Permalink
Include all client build artifacts in SSRManifest (#3678)
Browse files Browse the repository at this point in the history
* Include all client build artifacts in SSRManifest

* Adds a changeset
  • Loading branch information
matthewp authored Jun 22, 2022
1 parent 1192837 commit 8988454
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-otters-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix regression with SSRManifest and client assets
16 changes: 10 additions & 6 deletions packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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 });
Expand Down
7 changes: 7 additions & 0 deletions packages/astro/test/fixtures/ssr-scripts/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import preact from '@astrojs/preact';

// https://astro.build/config
export default defineConfig({
integrations: [preact()],
});
9 changes: 9 additions & 0 deletions packages/astro/test/fixtures/ssr-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/ssr-scripts",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/preact": "workspace:",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export default function() {
return (
<div>Hello world</div>
)
}
11 changes: 11 additions & 0 deletions packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions packages/astro/test/ssr-scripts.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8988454

Please sign in to comment.