0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

Server Islands - Handle base + trailingSlash ignore (#11712)

* Server Islands - Handle base + trailingSlash ignore

* Add a changeset
This commit is contained in:
Matthew Phillips 2024-08-15 04:34:25 -04:00 committed by GitHub
parent 4a2cb3d1a9
commit 791d809cbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix mixed use of base + trailingSlash in Server Islands

View file

@ -9,7 +9,7 @@ export default defineConfig({
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(), mdx()],
trailingSlash: 'always',
trailingSlash: process.env.TRAILING_SLASH ?? 'always',
experimental: {
serverIslands: true,
}

View file

@ -52,6 +52,26 @@ test.describe('Server islands', () => {
});
});
test.describe('Development - trailingSlash: ignore', () => {
let devServer;
test.beforeAll(async ({ astro }) => {
process.env.TRAILING_SLASH = 'ignore';
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
test('Load content from the server', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/base/'));
let el = page.locator('#island');
await expect(el, 'element rendered').toBeVisible();
await expect(el, 'should have content').toHaveText('I am an island');
});
});
test.describe('Production', () => {
let previewServer;

View file

@ -64,7 +64,8 @@ export function renderServerIsland(
const propsEncrypted = await encryptString(key, JSON.stringify(props));
const hostId = crypto.randomUUID();
const serverIslandUrl = `${result.base}_server-islands/${componentId}${result.trailingSlash === 'always' ? '/' : ''}`;
const slash = result.base.endsWith('/') ? '' : '/';
const serverIslandUrl = `${result.base}${slash}_server-islands/${componentId}${result.trailingSlash === 'always' ? '/' : ''}`;
destination.write(`<script async type="module" data-island-id="${hostId}">
let componentId = ${safeJsonStringify(componentId)};