diff --git a/src/content/docs/en/guides/upgrade-to/v6.mdx b/src/content/docs/en/guides/upgrade-to/v6.mdx index 1c52bb9506786..78b2b2d16c473 100644 --- a/src/content/docs/en/guides/upgrade-to/v6.mdx +++ b/src/content/docs/en/guides/upgrade-to/v6.mdx @@ -97,6 +97,20 @@ Astro v6.0 upgrades to Vite v7.0 as the development server and production bundle If you are using Vite-specific plugins, configuration, or APIs, check the [Vite migration guide](https://vite.dev/guide/migration) for their breaking changes and upgrade your project as needed. +### Vite Environment API + + + +Astro v6.0 introduces significant changes to how Astro manages different runtime environments (client, server, and prerender) after an internal refactor to use [Vite's new Environments API](https://vite.dev/guide/api-environment). + +Integration and adapter maintainers should pay special attention to changes affecting these parts of the Integration API and Adapter API (full details included below with other breaking changes to these APIs): + +- [integration hooks and HMR access patterns](#changed-integration-hooks-and-hmr-access-patterns-integration-api) +- [`SSRManifest` structure](#changed-ssrmanifest-interface-structure-adapter-api) +- [generating routes with `RouteData`](#removed-routedatagenerate-adapter-api) +- [routes with percent-encoded percent signs (e.g. `%25`)](#removed-percent-encoding-in-routes) +- [`astro:ssr-manifest` virtual module](#removed-astrossr-manifest-virtual-module-integration-api) + ## Legacy The following features are now considered legacy features. They should function normally but are no longer recommended and are in maintenance mode. They will see no future improvements and documentation will not be updated. These features will eventually be deprecated, and then removed entirely. @@ -452,6 +466,61 @@ import { Learn more about all utilities available in the [Actions API Reference](/en/reference/modules/astro-actions/). +### Removed: Percent-Encoding in routes + + + +In Astro 5.x, it was possible to include a percent-encoded percent sign (`%25`) in filenames. + +Astro 6.0 removes support for the characters `%25` in filenames for security reasons. This restriction prevents encoding-based security bypasses where `%25` decodes to `%`, potentially leading to ambiguous or invalid encoding sequences. + +#### What should I do? + +If you have route files with `%25` in the filename, rename them to use a different character: + +```bash del={1} ins={2} +src/pages/test%25file.astro +src/pages/test-file.astro +``` + +### Removed: `astro:ssr-manifest` virtual module (Integration API) + + + +In Astro 5.x, the deprecated `astro:ssr-manifest` virtual module could still be used to access configuration values. + +Astro 6.0 removes the `astro:ssr-manifest` virtual module entirely. It is no longer used by integrations or internally by Astro. The manifest is now passed directly through integration hooks and adapter APIs rather than through a virtual module. For build-specific manifest data, use the `astro:build:ssr` integration hook, which receives the manifest as a parameter. + +#### What should I do? + +If your integration or code imports from `astro:ssr-manifest`, use `astro:config/server` instead to access configuration values: + +```ts del={1} ins={2,3} +import { manifest } from 'astro:ssr-manifest'; +import { srcDir, outDir, root } from 'astro:config/server'; +// Use srcDir, outDir, root, etc. for configuration values +``` + +Learn more about [the `astro:config` virtual module](/en/reference/modules/astro-config/). + +### Removed: `RouteData.generate()` (Adapter API) + + + +In Astro 5.x, routes could be generated using the `generate()` method on `RouteData`. + +Astro 6.0 removes `RouteData.generate()` because route generation is now handled internally by Astro. + +#### What should I do? + +Remove any calls to `route.generate()` in your code. This method is no longer needed: + +```ts del={1} +const generated = route.generate(params); +``` + +Learn more about [the Adapter API](/en/reference/adapter-reference/). + ### Removed: `routes` on `astro:build:done` hook (Integration API) @@ -1051,6 +1120,76 @@ export function getStaticPaths() { Learn more about [dynamic SSG routes with `getStaticPaths()`](/en/guides/routing/#static-ssg-mode). +### Changed: Integration hooks and HMR access patterns (Integration API) + + + +In Astro 5.x, Astro relied on certain patterns for integration hooks and HMR access that were incompatible with or could be improved by integrating Vite's Environment API. + +Astro 6.0 uses Vite's new Environment API for build configuration and dev server interactions. This primarily enables dev mode in runtimes like workerd, but means that some integration hooks and HMR access patterns have changed. + +#### What should I do? + +**For integrations using `astro:build:setup`:** + +The hook is now called once with all environments configured (`ssr`, `client`, `prerender`), instead of being called separately for each build target. Remove the `target` parameter and use `vite.environments` to configure specific environments: + +```ts title="my-integration.mjs" del={3-7} ins={8-10} +{ + hooks: { + 'astro:build:setup': ({ target, vite }) => { + if (target === 'client') { + vite.build.minify = false; + } + } + 'astro:build:setup': ({ vite }) => { + vite.environments.client.build.minify = false; + } + } +} +``` + +**For dev toolbar and integration code accessing HMR:** + +Replace `server.hot.send()` with `server.environments.client.hot.send()`: + +```ts del={1} ins={2} +server.hot.send(event) +server.environments.client.hot.send(event) +``` + +Learn more about the [Vite Environment API](https://vite.dev/guide/api-environment) and Astro [integration hooks](/en/reference/integrations-reference/#astrobuildsetup). + +### Changed: `SSRManifest` interface structure (Adapter API) + + + +In Astro 5.x, path properties of the `SSRManifest` interface like `srcDir`, `outDir`, `cacheDir`, `publicDir`, `buildClientDir`, and `buildServerDir` were URL strings. + +Astro 6.0 changes the form of these path properties to `URL` objects instead of URL strings. With this change, several new properties are now available on the manifest, and others have been updated or removed. + +#### What should I do? + +If you were treating these path properties as strings, you will now need to handle the `URL` object. For example, you will now need to access the `href` property of the `URL` object: + +```ts del={2} ins={3} +// To retrieve the same format (e.g., "file:///path/to/src"), make the following change: +const srcPath = manifest.srcDir; +const srcPath = manifest.srcDir.href; +``` + +If you were accessing the `hrefRoot` property, you will need to remove it, as it is no longer available on the manifest. + +Update any use of `serverIslandMappings` and `sessionDriver`. These are now async methods: + +```ts del={1,2} ins={3,4} +const mappings = manifest.serverIslandMappings; +const driver = manifest.sessionDriver; +const mappings = await manifest.serverIslandMappings?.(); +const driver = await manifest.sessionDriver?.(); +``` + +Learn more about [the Adapter API](/en/reference/adapter-reference/). ### Changed: schema types are inferred instead of generated (Content Loader API) diff --git a/src/content/docs/en/reference/integrations-reference.mdx b/src/content/docs/en/reference/integrations-reference.mdx index effb14d6da7c6..5dac13f2e507e 100644 --- a/src/content/docs/en/reference/integrations-reference.mdx +++ b/src/content/docs/en/reference/integrations-reference.mdx @@ -73,7 +73,6 @@ interface AstroIntegration { 'astro:build:setup'?: (options: { vite: vite.InlineConfig; pages: Map; - target: 'client' | 'server'; updateConfig: (newConfig: vite.InlineConfig) => void; logger: AstroIntegrationLogger; }) => void | Promise; @@ -921,7 +920,6 @@ The address, family and port number supplied by the [Node.js Net module](https:/ 'astro:build:setup'?: (options: { vite: vite.InlineConfig; pages: Map; - target: 'client' | 'server'; updateConfig: (newConfig: vite.InlineConfig) => void; logger: AstroIntegrationLogger; }) => void | Promise; @@ -976,30 +974,6 @@ export default { } ``` -#### `target` option - -

- -**Type:** `'client' | 'server'` -

- -Builds are separated in two distinct phases: `client` and `server`. This option allow you to determine the current build phase. - -This can be used to perform an action only in a specific phase: - -```js -export default { - name: 'my-integration', - hooks: { - 'astro:build:setup': ({ target }) => { - if (target === "server") { - // do something in server build phase - } - }, - } -} -``` - #### `updateConfig()` option

@@ -1049,7 +1023,7 @@ export default {

-**Type:** [`SerializedSSRManifest`](https://github.com/withastro/astro/blob/3b10b97a4fecd1dfd959b160a07b5b8427fe40a7/packages/astro/src/core/app/types.ts#L91-L109) +**Type:** [`SerializedSSRManifest`](https://github.com/withastro/astro/blob/95a1969a05cc9c15f16dcf2177532882bb392581/packages/astro/src/core/app/types.ts#L126-L144)

Allows you to create a custom build by accessing the SSR manifest.