0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

Fix Server Islands in Vercel (#11491)

* Fix Server Islands in Vercel

* Add a changeset

* Get server islands pattern from the segments

* Move getPattern so it can be used at runtime

* Fix build
This commit is contained in:
Matthew Phillips 2024-07-18 11:03:39 -04:00 committed by GitHub
parent 26d1dcaf23
commit 7d1c5357d0
5 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,10 @@
import vercel from '@astrojs/vercel/serverless';
import { defineConfig } from 'astro/config';
export default defineConfig({
output: "server",
adapter: vercel(),
experimental: {
serverIslands: true,
}
});

View file

@ -0,0 +1,10 @@
{
"name": "@test/vercel-server-islands",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1 @@
<h1>I'm an island</h1>

View file

@ -0,0 +1,12 @@
---
import Island from '../components/Island.astro';
---
<html>
<head>
<title>One</title>
</head>
<body>
<h1>One</h1>
<Island server:defer />
</body>
</html>

View file

@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
describe('Server Islands', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/server-islands/',
});
await fixture.build();
});
it('server islands route is in the config', async () => {
const config = JSON.parse(
await fixture.readFile('../.vercel/output/config.json')
);
let found = null;
for(let route of config.routes) {
if(route.src?.includes('_server-islands')) {
found = route;
break;
}
}
assert.notEqual(found, null, 'Default server islands route included');
});
});