Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require the experimental flag to use server islands #11432

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/server-islands/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ export default defineConfig({
tailwind({ applyBaseStyles: false })
],
devToolbar: { enabled: false },
experimental: {
serverIslands: true,
}
});
3 changes: 3 additions & 0 deletions packages/astro/e2e/fixtures/server-islands/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export default defineConfig({
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(), mdx()],
experimental: {
serverIslands: true,
}
});
28 changes: 28 additions & 0 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,34 @@ export interface AstroUserConfig {
*/
schema?: EnvSchema;
};

/**
* @docs
* @name experimental.serverIslands
* @type {boolean}
* @default `false`
* @version 4.12.0
* @description
*
* Enables Server Islands, the ability to defer a component to render asynchronously after the page has already rendered.
*
* ```js
* {
* experimental: {
* serverIslands: true,
* },
* }
* ```
*
* Use the `server:defer` directive on any component, Astro or framework, and the component will not render initially.
*
* ```astro "server:defer"
* <Avatar server:defer />
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
* ```
*
* For a complete overview, and to give feedback on this experimental API, see the [Server Islands RFC](https://github.com/withastro/roadmap/pull/963).
*/
serverIslands?: boolean;
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const ASTRO_CONFIG_DEFAULTS = {
clientPrerender: false,
globalRoutePriority: false,
rewriting: false,
serverIslands: false,
},
} satisfies AstroUserConfig & { server: { open: boolean } };

Expand Down Expand Up @@ -529,6 +530,7 @@ export const AstroConfigSchema = z.object({
})
.strict()
.optional(),
serverIslands: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.serverIslands),
})
.strict(
`Invalid or outdated experimental feature.\nCheck for incorrect spelling or outdated Astro version.\nSee https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for a list of all current experiments.`
Expand Down Expand Up @@ -667,7 +669,7 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: string) {
'The value of `outDir` must not point to a path within the folder set as `publicDir`, this will cause an infinite loop',
})
.superRefine((configuration, ctx) => {
const { site, experimental, i18n, output } = configuration;
const { site, i18n, output } = configuration;
const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
if (hasDomains) {
if (!site) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function createVite(
astroDevToolbar({ settings, logger }),
vitePluginFileURL({}),
astroInternationalization({ settings }),
vitePluginServerIslands({ settings }),
settings.config.experimental.serverIslands && vitePluginServerIslands({ settings }),
astroContainer(),
],
publicDir: fileURLToPath(settings.config.publicDir),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineConfig({
output: 'hybrid',
integrations: [
svelte()
]
],
experimental: {
serverIslands: true,
}
});

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default defineConfig({
output: 'server',
integrations: [
svelte()
]
],
experimental: {
serverIslands: true,
}
});

Loading