Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
34 changes: 17 additions & 17 deletions astro.sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ export const sidebar = [
'reference/dev-toolbar-app-reference',
'reference/session-driver-reference',
'reference/font-provider-reference',
'reference/container-reference',
'reference/programmatic-reference',
],
}),
group('reference.experimental', {
items: [
'reference/experimental-flags',
'reference/experimental-flags/route-caching',
'reference/experimental-flags/client-prerender',
'reference/experimental-flags/content-intellisense',
'reference/experimental-flags/chrome-devtools-workspace',
'reference/experimental-flags/svg-optimization',
'reference/experimental-flags/queued-rendering',
'reference/experimental-flags/advanced-routing',
'reference/experimental-flags/logger',
],
}),
'reference/container-reference',
'reference/programmatic-reference',
'reference/advanced-routing',
'reference/route-caching',
Comment on lines +151 to +154

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually keep the experimental API at the end:

Suggested change
'reference/container-reference',
'reference/programmatic-reference',
'reference/advanced-routing',
'reference/route-caching',
'reference/advanced-routing',
'reference/route-caching',
'reference/container-reference',
'reference/programmatic-reference',

],
}),
group('reference.experimental', {
items: [
'reference/experimental-flags',
'reference/experimental-flags/client-prerender',
'reference/experimental-flags/content-intellisense',
'reference/experimental-flags/chrome-devtools-workspace',
'reference/experimental-flags/svg-optimization',
'reference/experimental-flags/queued-rendering',
'reference/experimental-flags/logger',
],
}),
'reference/legacy-flags',
'reference/error-reference',
],
Expand Down
68 changes: 59 additions & 9 deletions src/content/docs/en/guides/upgrade-to/v7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,74 @@ If you are using Vite-specific plugins, configuration, or APIs, check the [Vite

Most Astro users should be able to upgrade without any changes to their project code. This is primarily a breaking change for Astro integrations and plugins that depend on Vite internals.

### Rust Compiler
### Experimental Flags

The Rust-based Astro compiler, previously available as an experimental flag (`experimental.rustCompiler`), is now the default and only compiler in Astro 7. The Rust compiler delivers significantly faster build times compared to the previous Go-based compiler.
Experimental flags allow you to opt in to features while they are in early development. The following experimental flags have been removed in Astro 7.0 and are now stable, or the new default behavior.

##### What should I do?

No action is required for most projects. The Rust compiler is a drop-in replacement for the Go-based compiler.
Remove these experimental flags from your Astro config if you were previously using them:

If you had previously opted in to the Rust compiler via the experimental flag, you can now remove it from your configuration:

```js title="astro.config.mjs" del={4-6}
```js del={5-7} title="astro.config.mjs"
import { defineConfig } from 'astro/config';

export default defineConfig({
experimental: {
rustCompiler: true,
advancedRouting: true,
routeCaching: true,
},
})
```

#### Experimental features now stable:

- `rustCompiler`: The Rust-based Astro compiler is now the default and only compiler, replacing the previous Go-based compiler. No action is required for most projects. If you encounter any issues, please report them on [GitHub](https://github.com/withastro/astro/issues).

- `advancedRouting`: Advanced routing is now enabled by default. See the [advanced routing reference](/en/reference/advanced-routing/) for more information. Note that `src/fetch.ts` is now a [reserved file name](#reserved-file-name-srcfetchts).

- `routeCaching`: Route caching is now enabled by default for improved performance.

### Reserved file name: `src/fetch.ts`

Astro v7.0 introduces [advanced routing](/en/reference/advanced-routing/), which uses `src/fetch.ts` (or `src/fetch.js`) as a special file name, similar to `src/middleware.ts`. Astro will automatically import this file to configure routing behavior.

If your project already has a `src/fetch.ts` file used for other purposes, Astro will attempt to process it as an advanced routing configuration, which may cause unexpected errors.

#### What should I do?

If you have an existing `src/fetch.ts` file that is not related to advanced routing, you have two options:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it seems there are three options (rename the existing file, disable, or choose another name for Astro fetch file)

Suggested change
If you have an existing `src/fetch.ts` file that is not related to advanced routing, you have two options:
If you have an existing `src/fetch.ts` file that is not related to advanced routing, you have three options:


**Rename your file** to something else (e.g. `src/fetcher.ts`, `src/main.ts`), and update any imports that reference it.

**Disable advanced routing** by setting `fetchFile: null` in your Astro config:

```js title="astro.config.mjs" ins={4}
import { defineConfig } from 'astro/config';

export default defineConfig({
fetchFile: null,
});
```

You can also point `fetchFile` to a different file name if you want to use advanced routing but need to keep `src/fetch.ts` for another purpose:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And because we use bold for the first two options, maybe this should be also be in bold:

Suggested change
You can also point `fetchFile` to a different file name if you want to use advanced routing but need to keep `src/fetch.ts` for another purpose:
**Configure `fetchFile` with a different file name** if you want to use advanced routing but need to keep `src/fetch.ts` for another purpose:


```js title="astro.config.mjs" ins={4}
import { defineConfig } from 'astro/config';

export default defineConfig({
fetchFile: './src/router.ts',
});
```

If you encounter any issues with the Rust compiler, please report them on [GitHub](https://github.com/withastro/astro/issues).
### Removed: `@astrojs/db`

The `@astrojs/db` package has been removed in Astro v7.0 and is no longer maintained.

#### What should I do?

Remove `@astrojs/db` from your project's dependencies and replace it with one of the following alternatives:

- **Node.js built-in SQLite**: Node.js now includes a built-in [`node:sqlite`](https://nodejs.org/api/sqlite.html) module (available since Node.js v22.5.0). This is a good option if you are using the Node.js adapter and were using `@astrojs/db` for local SQLite storage.

- **[Drizzle ORM](https://orm.drizzle.team/)**: If you were using `@astrojs/db` for its Drizzle-based schema and query API, you can use Drizzle directly with any supported database.

- **Other database libraries**: Use any database library that suits your deployment platform (e.g. [Turso](https://turso.tech/), [PlanetScale](https://planetscale.com/), [Neon](https://neon.tech/)).
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Experimental advanced routing
title: Advanced routing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency nit: the other items are all suffixed by API, so it looks a bit odd that two of them are not.

Suggested change
title: Advanced routing
title: Advanced routing API

But, I wonder if this shouldn't be a guide (maybe in Routing) rather than a reference? Except "astro/fetch handler reference" which I think makes sense to have next to the other Runtime APIs (astro/app, astro/zod, etc.)

sidebar:
label: Advanced routing
i18nReady: true
Expand All @@ -8,35 +8,22 @@ i18nReady: true
import Since from '~/components/Since.astro'

<p>

**Type:** `boolean`<br />
**Default:** `false`<br />
<Since v="6.3.0" />
<Since v="7.0.0" />
</p>

Enables `src/app.ts` as a custom request pipeline entrypoint, giving you full control over how Astro handles incoming requests.
`src/fetch.ts` is a custom request pipeline entrypoint, giving you full control over how Astro handles incoming requests.

By default, Astro handles every request with a built-in pipeline that runs trailing-slash normalization, redirects, sessions, actions, user middleware, page rendering, i18n, and caching in a fixed order. Advanced routing lets you replace this pipeline with your own, composing Astro's built-in handler functions with custom logic in any order you choose.

```js title="astro.config.mjs"
import { defineConfig } from 'astro/config';

export default defineConfig({
experimental: {
advancedRouting: true,
},
});
```

## Creating `src/app.ts`
## Creating `src/fetch.ts`

When `advancedRouting` is enabled, create a `src/app.ts` (or `.js`, `.mjs`, `.mts`) file that default-exports an object with a `fetch` method. The `fetch` method receives a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and must return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response).
Create a `src/fetch.ts` (or `.js`, `.mjs`, `.mts`) file that default-exports an object with a `fetch` method. The `fetch` method receives a standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and must return a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response).

If no `src/app.ts` file exists (or `advancedRouting` is not enabled), Astro uses its built-in pipeline, which runs all features automatically.
If no `src/fetch.ts` file exists, Astro uses its built-in pipeline, which runs all features automatically.

You can optionally import the `Fetchable` type from `astro` to type-check your entrypoint:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import type { Fetchable } from 'astro';

export default {
Expand All @@ -48,37 +35,29 @@ export default {

### Customizing the entrypoint file

By default, Astro looks for `src/app.ts` as the advanced routing entrypoint. Pass an object to `advancedRouting` with a `fetchFile` option to use a different file:
By default, Astro looks for `src/fetch.ts` as the advanced routing entrypoint. Set the `fetchFile` option to use a different file:

```js title="astro.config.mjs"
export default defineConfig({
experimental: {
advancedRouting: {
fetchFile: 'fetch.ts',
},
},
fetchFile: 'handler',
});
```

With this configuration, Astro will look for `src/fetch.ts` instead of `src/app.ts`.
With this configuration, Astro will look for `src/handler.ts` instead of `src/fetch.ts`.

Set `fetchFile` to `null` to disable the entrypoint entirely. This is useful if you already have a `src/app.ts` file used for other purposes:
Set `fetchFile` to `null` to disable the entrypoint entirely. This is useful if you already have a `src/fetch.ts` file used for other purposes:

```js title="astro.config.mjs"
export default defineConfig({
experimental: {
advancedRouting: {
fetchFile: null,
},
},
fetchFile: null,
});
```

### Using `astro()`

The easiest way to get started is with the [`astro()` handler](#astro), which runs Astro's full built-in pipeline (sessions, cache, redirects, trailing-slash, actions, middleware, pages, and i18n) in the default order. This lets you add custom logic before or after Astro without changing how the internal pipeline works:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import { FetchState, astro } from 'astro/fetch';

export default {
Expand Down Expand Up @@ -112,7 +91,7 @@ For many use cases, such as adding auth guards, request logging, and custom head

When you need more control over the pipeline order, or want to omit certain features entirely, you can compose individual handler functions from `astro/fetch`:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import {
FetchState,
sessions,
Expand Down Expand Up @@ -147,7 +126,7 @@ The main benefit of advanced routing is the ability to insert custom logic anywh

The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages, such as running custom code after actions but before page rendering, compose the individual handlers instead:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import {
FetchState,
actions,
Expand Down Expand Up @@ -343,7 +322,7 @@ try {

The all-in-one handler that runs the full Astro pipeline (sessions, cache, redirects, trailing-slash, actions, middleware, pages, and i18n) in the default order. Use this when you want to add logic before or after Astro without changing the internal pipeline order:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import { FetchState, astro } from 'astro/fetch';

export default {
Expand Down Expand Up @@ -442,7 +421,7 @@ Handles redirect routes defined in your [Astro config](/en/reference/configurati
**Type:** <code>(state: <a href="#fetchstate">FetchState</a>, next: () => Promise\<Response\>) => Promise\<Response\></code>
</p>

Wraps a render callback with [cache](/en/reference/experimental-flags/route-caching/) provider logic. Handles runtime caching, CDN-based providers, and the no-cache case.
Wraps a render callback with [cache](/en/reference/route-caching/) provider logic. Handles runtime caching, CDN-based providers, and the no-cache case.

### `trailingSlash()`

Expand All @@ -455,9 +434,9 @@ Checks if the request pathname needs [trailing-slash](/en/reference/configuratio

## Using with Hono

Astro also provides Hono-compatible wrappers for all handler functions via `astro/hono`. If you prefer to use [Hono](https://hono.dev/) as your routing framework, you can export a Hono app from `src/app.ts`:
Astro also provides Hono-compatible wrappers for all handler functions via `astro/hono`. If you prefer to use [Hono](https://hono.dev/) as your routing framework, you can export a Hono app from `src/fetch.ts`:

```ts title="src/app.ts"
```ts title="src/fetch.ts"
import { Hono } from 'hono';
import { logger } from 'hono/logger';
import { actions, middleware, pages, i18n } from 'astro/hono';
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/en/reference/content-loader-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ export function myLoader(config): LiveLoader<Product, ProductEntryFilter, Produc
}
```

You can then use these hints in your pages. If you have [experimental route caching](/en/reference/experimental-flags/route-caching/) enabled, pass cache hints directly to `Astro.cache.set()`:
You can then use these hints in your pages. If you have [route caching](/en/reference/route-caching/) enabled, pass cache hints directly to `Astro.cache.set()`:

```astro title="src/pages/store/[id].astro"
---
Expand Down Expand Up @@ -662,7 +662,7 @@ if (cacheHint?.lastModified) {
```

:::note
Cache hints do not automatically cause the response to be cached by Astro. They provide values you can pass to [route caching](/en/reference/experimental-flags/route-caching/) or use to implement your own caching strategy.
Cache hints do not automatically cause the response to be cached by Astro. They provide values you can pass to [route caching](/en/reference/route-caching/) or use to implement your own caching strategy.
:::

## Distributing your loader
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/en/reference/modules/astro-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ const { error } = await getLiveCollection('products');

An object providing guidance on how to cache this collection.

If you have [experimental route caching](/en/reference/experimental-flags/route-caching/) enabled, pass the cache hint directly to `Astro.cache.set()`:
If you have [route caching](/en/reference/route-caching/) enabled, pass the cache hint directly to `Astro.cache.set()`:

```astro title="src/pages/shop/index.astro"
---
Expand Down Expand Up @@ -642,7 +642,7 @@ if (error) {

An object providing data that can be used to inform a caching strategy.

If you have [experimental route caching](/en/reference/experimental-flags/route-caching/) enabled, pass the cache hint directly to `Astro.cache.set()`:
If you have [route caching](/en/reference/route-caching/) enabled, pass the cache hint directly to `Astro.cache.set()`:

```astro title="src/pages/shop/[id].astro"
---
Expand Down
Loading
Loading