Skip to content

Commit

Permalink
Merge branch 'main' of github.com:withastro/astro into astro-11454-im…
Browse files Browse the repository at this point in the history
…prove-ssr-performance
  • Loading branch information
MatthewLymer committed Feb 10, 2025
2 parents 095b21c + 9d56602 commit 50b4a7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nice-poems-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes and issue where a server island component returns 404 when `base` is configured in i18n project.
3 changes: 2 additions & 1 deletion packages/astro/src/core/routing/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export function isRouteServerIsland(route: RouteData): boolean {
*/
export function isRequestServerIsland(request: Request, base = ''): boolean {
const url = new URL(request.url);
const pathname = url.pathname.slice(base.length);
const pathname =
base === '/' ? url.pathname.slice(base.length) : url.pathname.slice(base.length + 1);

return pathname.startsWith(SERVER_ISLAND_BASE_PREFIX);
}
Expand Down
27 changes: 27 additions & 0 deletions packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2194,3 +2194,30 @@ describe('i18n routing with server islands', () => {
assert.equal(serverIslandScript.length, 1, 'has the island script');
});
});

describe('i18n routing with server islands and base path', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
/** @type {import('./test-utils').DevServer} */
let devServer;

before(async () => {
fixture = await loadFixture({
root: './fixtures/i18n-server-island/',
base: '/custom',
});
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('should render the en locale with server island', async () => {
const res = await fixture.fetch('/custom/en/island');
const html = await res.text();
const $ = cheerio.load(html);
const serverIslandScript = $('script[data-island-id]');
assert.equal(serverIslandScript.length, 1, 'has the island script');
});
});

0 comments on commit 50b4a7e

Please sign in to comment.