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
This commit is contained in:
parent
4f7f20616e
commit
1aeabe4170
6 changed files with 66 additions and 4 deletions
5
.changeset/fast-carpets-float.md
Normal file
5
.changeset/fast-carpets-float.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix Astro.params not having values when using base in SSR
|
|
@ -168,7 +168,7 @@ export class App {
|
||||||
status = 200
|
status = 200
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const manifest = this.#manifest;
|
const pathname = '/' + this.removeBase(url.pathname);
|
||||||
const info = this.#routeDataToRouteInfo.get(routeData!)!;
|
const info = this.#routeDataToRouteInfo.get(routeData!)!;
|
||||||
const links = createLinkStylesheetElementSet(info.links);
|
const links = createLinkStylesheetElementSet(info.links);
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ export class App {
|
||||||
const ctx = createRenderContext({
|
const ctx = createRenderContext({
|
||||||
request,
|
request,
|
||||||
origin: url.origin,
|
origin: url.origin,
|
||||||
pathname: url.pathname,
|
pathname,
|
||||||
scripts,
|
scripts,
|
||||||
links,
|
links,
|
||||||
route: routeData,
|
route: routeData,
|
||||||
|
@ -215,12 +215,13 @@ export class App {
|
||||||
status = 200
|
status = 200
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
|
const pathname = '/' + this.removeBase(url.pathname);
|
||||||
const handler = mod as unknown as EndpointHandler;
|
const handler = mod as unknown as EndpointHandler;
|
||||||
|
|
||||||
const ctx = createRenderContext({
|
const ctx = createRenderContext({
|
||||||
request,
|
request,
|
||||||
origin: url.origin,
|
origin: url.origin,
|
||||||
pathname: url.pathname,
|
pathname,
|
||||||
route: routeData,
|
route: routeData,
|
||||||
status,
|
status,
|
||||||
});
|
});
|
||||||
|
|
8
packages/astro/test/fixtures/ssr-params/package.json
vendored
Normal file
8
packages/astro/test/fixtures/ssr-params/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "@test/ssr-params",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
12
packages/astro/test/fixtures/ssr-params/src/pages/[category].astro
vendored
Normal file
12
packages/astro/test/fixtures/ssr-params/src/pages/[category].astro
vendored
Normal file
|
@ -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>
|
30
packages/astro/test/ssr-params.test.js
Normal file
30
packages/astro/test/ssr-params.test.js
Normal file
|
@ -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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -2280,6 +2280,12 @@ importers:
|
||||||
dependencies:
|
dependencies:
|
||||||
astro: link:../../..
|
astro: link:../../..
|
||||||
|
|
||||||
|
packages/astro/test/fixtures/ssr-params:
|
||||||
|
specifiers:
|
||||||
|
astro: workspace:*
|
||||||
|
dependencies:
|
||||||
|
astro: link:../../..
|
||||||
|
|
||||||
packages/astro/test/fixtures/ssr-partytown:
|
packages/astro/test/fixtures/ssr-partytown:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@astrojs/partytown': workspace:*
|
'@astrojs/partytown': workspace:*
|
||||||
|
@ -18434,7 +18440,7 @@ packages:
|
||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 18.11.9
|
'@types/node': 18.11.9
|
||||||
esbuild: 0.15.18
|
esbuild: 0.15.14
|
||||||
postcss: 8.4.19
|
postcss: 8.4.19
|
||||||
resolve: 1.22.1
|
resolve: 1.22.1
|
||||||
rollup: 2.79.1
|
rollup: 2.79.1
|
||||||
|
|
Loading…
Reference in a new issue