summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2022-12-08 08:08:27 -0500
committerGravatar GitHub <noreply@github.com> 2022-12-08 08:08:27 -0500
commit1aeabe417077505bc0cdb8d2e47366ddbc616072 (patch)
tree39a618e9d23fb63db665f5a9ba3575a2854838e3
parent4f7f20616ed2b63f94ebf43bc5fdc1be55062a94 (diff)
downloadastro-1aeabe417077505bc0cdb8d2e47366ddbc616072.tar.gz
astro-1aeabe417077505bc0cdb8d2e47366ddbc616072.tar.zst
astro-1aeabe417077505bc0cdb8d2e47366ddbc616072.zip
Fix Astro.params not having values when using base in SSR (#5553)
* Fix Astro.params not having values when using base in SSR * Adding a changeseet
-rw-r--r--.changeset/fast-carpets-float.md5
-rw-r--r--packages/astro/src/core/app/index.ts7
-rw-r--r--packages/astro/test/fixtures/ssr-params/package.json8
-rw-r--r--packages/astro/test/fixtures/ssr-params/src/pages/[category].astro12
-rw-r--r--packages/astro/test/ssr-params.test.js30
-rw-r--r--pnpm-lock.yaml8
6 files changed, 66 insertions, 4 deletions
diff --git a/.changeset/fast-carpets-float.md b/.changeset/fast-carpets-float.md
new file mode 100644
index 000000000..0d565296d
--- /dev/null
+++ b/.changeset/fast-carpets-float.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix Astro.params not having values when using base in SSR
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts
index 188562e9d..c7b8616ef 100644
--- a/packages/astro/src/core/app/index.ts
+++ b/packages/astro/src/core/app/index.ts
@@ -168,7 +168,7 @@ export class App {
status = 200
): Promise<Response> {
const url = new URL(request.url);
- const manifest = this.#manifest;
+ const pathname = '/' + this.removeBase(url.pathname);
const info = this.#routeDataToRouteInfo.get(routeData!)!;
const links = createLinkStylesheetElementSet(info.links);
@@ -190,7 +190,7 @@ export class App {
const ctx = createRenderContext({
request,
origin: url.origin,
- pathname: url.pathname,
+ pathname,
scripts,
links,
route: routeData,
@@ -215,12 +215,13 @@ export class App {
status = 200
): Promise<Response> {
const url = new URL(request.url);
+ const pathname = '/' + this.removeBase(url.pathname);
const handler = mod as unknown as EndpointHandler;
const ctx = createRenderContext({
request,
origin: url.origin,
- pathname: url.pathname,
+ pathname,
route: routeData,
status,
});
diff --git a/packages/astro/test/fixtures/ssr-params/package.json b/packages/astro/test/fixtures/ssr-params/package.json
new file mode 100644
index 000000000..4fbafaafa
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-params/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "@test/ssr-params",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "astro": "workspace:*"
+ }
+}
diff --git a/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro b/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro
new file mode 100644
index 000000000..bdaa1f965
--- /dev/null
+++ b/packages/astro/test/fixtures/ssr-params/src/pages/[category].astro
@@ -0,0 +1,12 @@
+---
+const { category } = Astro.params
+---
+<html>
+ <head>
+ <title>Testing</title>
+ </head>
+ <body>
+ <h1>Testing</h1>
+ <h2 class="category">{ category }</h2>
+ </body>
+</html>
diff --git a/packages/astro/test/ssr-params.test.js b/packages/astro/test/ssr-params.test.js
new file mode 100644
index 000000000..93e5f956b
--- /dev/null
+++ b/packages/astro/test/ssr-params.test.js
@@ -0,0 +1,30 @@
+import { expect } from 'chai';
+import * as cheerio from 'cheerio';
+import { loadFixture } from './test-utils.js';
+import testAdapter from './test-adapter.js';
+
+describe('Astro.params in SSR', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/ssr-params/',
+ adapter: testAdapter(),
+ output: 'server',
+ base: '/users/houston/',
+ });
+ await fixture.build();
+ });
+
+ it('Params are passed to component', async () => {
+ const app = await fixture.loadTestAdapterApp();
+ const request = new Request('http://example.com/users/houston/food');
+ const response = await app.render(request);
+ expect(response.status).to.equal(200);
+ const html = await response.text();
+ const $ = cheerio.load(html);
+ expect($('.category').text()).to.equal('food');
+ });
+
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f41745f3f..b3f2bf344 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2280,6 +2280,12 @@ importers:
dependencies:
astro: link:../../..
+ packages/astro/test/fixtures/ssr-params:
+ specifiers:
+ astro: workspace:*
+ dependencies:
+ astro: link:../../..
+
packages/astro/test/fixtures/ssr-partytown:
specifiers:
'@astrojs/partytown': workspace:*
@@ -18434,7 +18440,7 @@ packages:
optional: true
dependencies:
'@types/node': 18.11.9
- esbuild: 0.15.18
+ esbuild: 0.15.14
postcss: 8.4.19
resolve: 1.22.1
rollup: 2.79.1