summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-06-22 11:35:54 -0400
committerGravatar GitHub <noreply@github.com> 2022-06-22 11:35:54 -0400
commit898845402cd82995bd4878c93d3ccfcce89ebf27 (patch)
treec96f5b556bea4e60fa4b4753dbe211237ed06992
parent119283775a098f4a23910dc9f8337fa78434eac5 (diff)
downloadastro-898845402cd82995bd4878c93d3ccfcce89ebf27.tar.gz
astro-898845402cd82995bd4878c93d3ccfcce89ebf27.tar.zst
astro-898845402cd82995bd4878c93d3ccfcce89ebf27.zip
Include all client build artifacts in SSRManifest (#3678)
* Include all client build artifacts in SSRManifest * Adds a changeset
-rw-r--r--.changeset/unlucky-otters-agree.md5
-rw-r--r--packages/astro/src/core/build/vite-plugin-ssr.ts16
-rw-r--r--packages/astro/test/fixtures/ssr-scripts/astro.config.mjs7
-rw-r--r--packages/astro/test/fixtures/ssr-scripts/package.json9
-rw-r--r--packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx6
-rw-r--r--packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro11
-rw-r--r--packages/astro/test/ssr-scripts.test.js27
-rw-r--r--pnpm-lock.yaml8
8 files changed, 83 insertions, 6 deletions
diff --git a/.changeset/unlucky-otters-agree.md b/.changeset/unlucky-otters-agree.md
new file mode 100644
index 000000000..2da789e51
--- /dev/null
+++ b/.changeset/unlucky-otters-agree.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix regression with SSRManifest and client assets
diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts
index e543e925e..ce386872b 100644
--- a/packages/astro/src/core/build/vite-plugin-ssr.ts
+++ b/packages/astro/src/core/build/vite-plugin-ssr.ts
@@ -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 });
diff --git a/packages/astro/test/fixtures/ssr-scripts/astro.config.mjs b/packages/astro/test/fixtures/ssr-scripts/astro.config.mjs
new file mode 100644
index 000000000..08916b1fe
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-scripts/astro.config.mjs
@@ -0,0 +1,7 @@
+import { defineConfig } from 'astro/config';
+import preact from '@astrojs/preact';
+
+// https://astro.build/config
+export default defineConfig({
+ integrations: [preact()],
+});
diff --git a/packages/astro/test/fixtures/ssr-scripts/package.json b/packages/astro/test/fixtures/ssr-scripts/package.json
new file mode 100644
index 000000000..2050dfbec
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-scripts/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@test/ssr-scripts",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/preact": "workspace:",
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx b/packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx
new file mode 100644
index 000000000..70279a587
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-scripts/src/components/Hello.jsx
@@ -0,0 +1,6 @@
+
+export default function() {
+ return (
+ <div>Hello world</div>
+ )
+}
diff --git a/packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro b/packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro
new file mode 100644
index 000000000..8b27cdd3b
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-scripts/src/pages/index.astro
@@ -0,0 +1,11 @@
+---
+import Hello from '../components/Hello.jsx';
+---
+<html lang="en">
+ <head>
+ <title>Astro</title>
+ </head>
+ <body>
+ <Hello client:load />
+ </body>
+</html>
diff --git a/packages/astro/test/ssr-scripts.test.js b/packages/astro/test/ssr-scripts.test.js
new file mode 100644
index 000000000..f44099e41
--- /dev/null
+++ b/packages/astro/test/ssr-scripts.test.js
@@ -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);
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 72634a6a1..254f0bcb6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -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:*