Skip to content
Merged
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
1 change: 1 addition & 0 deletions astro.sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const sidebar = [
'reference/experimental-flags/chrome-devtools-workspace',
'reference/experimental-flags/svg-optimization',
'reference/experimental-flags/collection-storage',
'reference/experimental-flags/incremental-build',
],
}),
'reference/legacy-flags',
Expand Down
11 changes: 6 additions & 5 deletions src/content/docs/en/guides/build-with-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,20 @@ The same technology that powers Astro's MCP server is also available as a chatbo

<p><Since v="7.0.0" /></p>

When an AI coding agent is detected, `astro dev` automatically starts the dev server as a detached background process. This prevents the dev server from blocking the agent's terminal and allows it to continue working while the server runs.
When an AI coding agent is detected, `astro dev` and, since v7.2.0, `astro preview` automatically start the server as a detached background process. This prevents the server from blocking the agent's terminal and allows it to continue working while the server runs.

A lock file (`.astro/dev.json`) is written when the dev server starts, recording the server's URL, port, and PID. This prevents duplicate servers from being started for the same project.
A lock file (`.astro/dev.json` or `.astro/preview.json`) is written when the server starts, recording the server's URL, port, and PID. This prevents duplicate servers from being started for the same project.

If you are not using an AI coding agent, `astro dev` starts in the foreground process and logs to the terminal.
If you are not using an AI coding agent, the server starts in the foreground process and logs to the terminal.

To opt out of automatic background mode, set the `ASTRO_DEV_BACKGROUND` environment variable before running `astro dev`:
To opt out of automatic background mode, set the `ASTRO_DEV_BACKGROUND` or `ASTRO_PREVIEW_BACKGROUND` environment variable before running the command:

```shell
ASTRO_DEV_BACKGROUND=0 astro dev
ASTRO_PREVIEW_BACKGROUND=0 astro preview
```

<ReadMore>See the [CLI reference](/en/reference/cli-reference/#astro-dev) for the full list of `astro dev` flags and subcommands.</ReadMore>
<ReadMore>See the CLI reference for the full list of flags and subcommands for [`astro dev`](/en/reference/cli-reference/#astro-dev) and [`astro preview`](/en/reference/cli-reference/#astro-preview).</ReadMore>

### Health endpoint

Expand Down
25 changes: 23 additions & 2 deletions src/content/docs/en/guides/integrations-guide/cloudflare.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ It also accepts the following:
### `imageService`

<p>
**Type:** `'passthrough' | 'cloudflare' | 'cloudflare-binding' | 'compile' | 'custom' | { build: 'compile', runtime?: 'cloudflare-binding' | 'passthrough' }`<br />
**Type:** `'passthrough' | 'cloudflare' | 'cloudflare-binding' | 'compile' | 'custom' | { build: 'compile' | 'cloudflare-binding', runtime?: 'cloudflare-binding' | 'passthrough' }`<br />
**Default:** `'cloudflare-binding'`
</p>

Expand All @@ -128,7 +128,11 @@ Determines which image service is used by the adapter. The adapter will default
- **`compile`:** Uses the [configured image service](/en/reference/configuration-reference/#imageservice) or falls back to a combination of internal dependencies to transform images locally at build time for prerendered routes. The noop `passthrough` option is configured for on-demand rendered pages.
- **`custom`:** Uses the [configured image service](/en/reference/configuration-reference/#imageservice) (defaults to Sharp) to process assets at build time for prerendered routes. Bundles the image service for runtime image handling, without checking its compatibility with Cloudflare's `workerd` runtime.

It is also possible to configure your image service as an object, setting both a build time and runtime service independently. Currently, `'compile'` is the only available build-time option. The supported runtime options are `'passthrough'` (default) and `'cloudflare-binding'`:
<p><Since v="14.2.0" pkg="@astrojs/cloudflare" /></p>

You can also configure the image service as an object by providing a build-time service (`compile` or `cloudflare-binding`) and, optionally, a runtime service (`passthrough` or `cloudflare-binding`).

When the runtime service is omitted, its default value depends on the configured build-time service. It falls back to `'passthrough'` for `build: 'compile'` and to `'cloudflare-binding'` for `build: 'cloudflare-binding'`.

```js title="astro.config.mjs" ins={6}
import { defineConfig } from 'astro/config';
Expand All @@ -141,6 +145,21 @@ export default defineConfig({
});
```

Using `imageService: 'cloudflare-binding'` enables image optimization using the [Cloudflare Images binding](https://developers.cloudflare.com/images/transform-images/bindings/) only at runtime.

To opt in to build-time image optimization with the binding during `workerd` prerendering, set `build` to `'cloudflare-binding'`. If the binding fails to transform an image at build time, the adapter falls back to the [configured image service](/en/reference/configuration-reference/#imageservice) (defaults to Sharp).

```js title="astro.config.mjs" ins={6}
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
adapter: cloudflare({
imageService: { build: 'cloudflare-binding', runtime: 'cloudflare-binding' }
}),
});
```

### `sessionKVBindingName`

<p>
Expand Down Expand Up @@ -354,6 +373,8 @@ const cart = await Astro.session?.get('cart');

By default, the KV binding is named `SESSION`. To use a different name, set the [`sessionKVBindingName`](#sessionkvbindingname) option in the adapter config.

If your project does not use sessions, you can set [`session: false`](/en/guides/sessions/#disabling-sessions) in your Astro config. The adapter will not configure a KV binding, no KV namespace will be provisioned when you deploy, and the session runtime will be excluded from your Worker bundle.

:::note
Writes to Cloudflare KV are [eventually consistent](https://developers.cloudflare.com/kv/concepts/how-kv-works/#consistency) between regions. This means that changes are available immediately within the same region but may take up to 60 seconds to propagate globally. This won't affect most users as they are unlikely to switch regions between requests, but it may be a consideration for some use cases, such as VPN users.
:::
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/en/guides/integrations-guide/netlify.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ The Astro [Sessions API](/en/guides/sessions/) allows you to easily store user d

Astro automatically configures [Netlify Blobs](https://docs.netlify.com/blobs/overview/) for session storage when using the Netlify adapter. If you would prefer to use a different session storage driver, you can specify it in your Astro config. See [the `session` configuration reference](/en/reference/configuration-reference/#sessiondriver) for more details.

If your project does not use sessions, you can set [`session: false`](/en/guides/sessions/#disabling-sessions) in your Astro config. The adapter will not configure Netlify Blobs for session storage, and the session runtime will be excluded from your function bundle.

### Caching Pages

On-demand rendered pages without any dynamic content can be cached to improve performance and lower resource usage.
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/en/guides/integrations-guide/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ The Astro [Sessions API](/en/guides/sessions/) allows you to easily store user d

Astro uses the local filesystem for session storage when using the Node adapter. If you would prefer to use a different session storage driver, you can specify it in your Astro config. See [the `session` configuration reference](/en/reference/configuration-reference/#sessiondriver) for more details.

If your project does not use sessions, you can set [`session: false`](/en/guides/sessions/#disabling-sessions) in your Astro config. The adapter will not configure the filesystem session driver, and the session runtime will be excluded from your server bundle.

## Environment variables

When using the [`astro:env`](/en/guides/environment-variables/#type-safe-environment-variables) secrets or `process.env` at runtime, neither Astro nor the adapter loads environment variables for you.
Expand Down
18 changes: 18 additions & 0 deletions src/content/docs/en/guides/sessions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ The following example takes advantage of [Unstorage compatibility](/en/reference
```
</Steps>

### Disabling sessions

<p>
<Since v="7.2.0" />
</p>

The session runtime is automatically excluded from your server bundle whenever no session driver is configured. Setting `session: false` additionally tells your adapter not to provide its default driver, opting your project out of session support entirely:

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

export default defineConfig({
session: false,
});
```

Adapters that normally provide a default session driver (e.g. [Node](/en/guides/integrations-guide/node/#sessions), [Cloudflare](/en/guides/integrations-guide/cloudflare/#sessions), and [Netlify](/en/guides/integrations-guide/netlify/#sessions)) will not configure one. This can be useful for serverless and edge runtimes, where a smaller bundle reduces cold start time.

## Interacting with session data

The [`session` object](/en/reference/api-reference/#session) allows you to interact with the stored user state (e.g. adding items to a shopping cart) and the session ID (e.g. deleting the session ID cookie when logging out). The object is accessible as `Astro.session` in your Astro components and pages and as `context.session` object in API endpoints, middleware, and actions.
Expand Down
12 changes: 11 additions & 1 deletion src/content/docs/en/reference/adapter-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ Describes the function an adapter should export to start a preview server when [

<p>

**Type:** `{ host?: string; port: number; closed(): Promise<void>; stop(): Promise<void>; }`
**Type:** `{ host?: string; port: number; urls?: { local: string[]; network: string[] }; closed(): Promise<void>; stop(): Promise<void>; }`
</p>

Describes an instance of a preview server for the adapter.
Expand All @@ -1062,6 +1062,16 @@ Defines the host the preview server is listening on.

Defines the port the preview server is listening on.

#### `PreviewServer.urls`

<p>

**Type:** `{ local: string[]; network: string[] } | undefined`<br />
<Since v="7.2.0" />
</p>

Defines the resolved URLs the preview server is listening on, grouped into `local` (loopback addresses) and `network` (LAN and public addresses). Astro uses these to record the server's address in the lock file [when the preview server runs in the background](/en/reference/cli-reference/#--background).

#### `PreviewServer.closed()`

<p>
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/en/reference/api-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -893,15 +893,15 @@ Allows customizing how the cookie is serialized.

<p>

**Type:** `AstroSession`
**Type:** `AstroSession | undefined`

<Since v="5.7.0" />

</p>

`session` is an object that allows data to be stored between requests for [routes rendered on demand](/en/guides/on-demand-rendering/). It is associated with a cookie that contains the session ID only: the data itself is not stored in the cookie.

The session is created when first used, and the session cookie is automatically set. The `session` object is `undefined` if no session storage has been configured, or if the current route is prerendered, and will log an error if you try to use it.
The session is created when first used, and the session cookie is automatically set. The `session` object is `undefined` and will log an error when used in the following cases: no session storage has been configured, [sessions are disabled](/en/guides/sessions/#disabling-sessions), or the current route is prerendered.

See [the session guide](/en/guides/sessions/) for more information on how to use sessions in your Astro project.

Expand Down
88 changes: 48 additions & 40 deletions src/content/docs/en/reference/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,6 @@ The following hotkeys can be used in the terminal where the Astro development se

The command accepts [common flags](#common-flags) and the following additional flags.

#### `--background`

Starts the dev server as a detached background process and enables [JSON logging](#--json). This flag is provided automatically when an AI agent is detected. You can also use it manually:

```shell
astro dev --background
```

If a server is already running for the project, the command prints the existing server's info and exits without starting a new one. Use the `--force` flag to stop the existing server and start a new one.

```shell
astro dev --background --force
```

<ReadMore>See [Background mode for AI coding agents](/en/guides/build-with-ai/#background-mode) for more about automatic agent detection and the health endpoint.</ReadMore>

#### `--ignore-lock`

<p><Since v="7.1.0" /></p>
Expand All @@ -228,32 +212,10 @@ Starts the dev server without checking or writing the lock file used to detect o
astro dev --ignore-lock --port 4322
```

The new server is not tracked by `astro dev stop`, `astro dev status`, or `astro dev logs`.
The new server is not tracked by the [`stop`, `status`, or `logs` subcommands](#common-subcommands).

When combined with `--background` (including when triggered by an AI coding agent) or `--force`, an error is thrown, as both rely on the lock file.

<h3>Subcommands</h3>

<p><Since v="7.0.0" /></p>

#### `astro dev stop`

Stops a running background dev server. Sends `SIGTERM` and waits up to 5 seconds for the server to exit gracefully. If the process is still running after that, it escalates to `SIGKILL`.

#### `astro dev status`

Checks whether a background dev server is running and displays its URL, PID, and uptime.

#### `astro dev logs`

Displays logs from a background dev server. Only works when the server was started with `astro dev --background`, since foreground servers write logs directly to the terminal.

##### Flags

###### `--follow` (`-f`)

Streams new log output as it's written, similar to `tail -f`. Without this flag, the current log file contents are printed and the command exits.

## `astro build`

Builds your site for deployment. By default, this will generate static files and place them in a `dist/` directory. If any routes are [rendered on demand](/en/guides/on-demand-rendering/), this will generate the necessary server files to serve your site.
Expand All @@ -278,7 +240,7 @@ The following hotkeys can be used in the terminal where the Astro preview server
- `o` + `enter` to open your Astro site in the browser.
- `q` + `enter` to quit the preview server.

The `astro preview` command can be combined with the [common flags](#common-flags) documented below to further control the preview experience.
The `astro preview` command can be combined with the [common flags](#common-flags) documented below to further control the preview experience. Since v7.2.0, it also accepts the [`--background` flag](#--background) and the [`stop`, `status`, and `logs` subcommands](#common-subcommands) to manage a background preview server.

## `astro check`

Expand Down Expand Up @@ -463,6 +425,30 @@ astro create-key

Set this key as the `ASTRO_KEY` environment variable (e.g. in a `.env` file) and include it in your CI/CD or host’s build settings when you need [a constant encryption key for your server islands](/en/guides/server-islands/#reusing-the-encryption-key) for situations like rolling deployments, multi-region hosting or a CDN that caches pages containing server islands.

## Common subcommands

<p><Since v="7.0.0" /></p>

The commands [`astro dev`](#astro-dev) and, since version v7.2.0, [`astro preview`](#astro-preview) accept the following subcommands to manage a [background server](#--background).

### `stop`

Stops a running background server. Sends `SIGTERM` and waits up to 5 seconds for the server to exit gracefully. If the process is still running after that, it escalates to `SIGKILL`.

### `status`

Checks whether a background server is running and displays its URL, PID, and uptime.

### `logs`

Displays logs from a background server. Only works when the server was started with the [`--background` flag](#--background), since foreground servers write logs directly to the terminal.

#### Flags

##### `--follow` (`-f`)

Streams new log output as it's written, similar to `tail -f`. Without this flag, the current log file contents are printed and the command exits.

## Common flags

### `--root <path>`
Expand Down Expand Up @@ -546,6 +532,28 @@ Enables silent logging, which will run the server without any console output.

Automatically opens the app in the browser on server start. Can be passed a full URL string (e.g. `--open http://example.com`) or a pathname (e.g. `--open /about`) to specify the URL to open.

### `--background`

<p><Since v="7.0.0" /></p>

Starts the dev server, or the preview server since v7.2.0, as a detached background process and enables [JSON logging](#--json).

When the server starts, Astro writes a lock file (`.astro/dev.json` or `.astro/preview.json`) to record the server's URL, port, and PID. This avoids launching many instances of the server for the same project.

This flag is provided automatically when an AI agent is detected. You can also use it manually:

```shell
astro dev --background
```

If a server is already running for the project, the command prints the existing server's info and exits without starting a new one. Use the `--force` flag to stop the existing server and start a new one.

```shell
astro dev --background --force
```

<ReadMore>See [Background mode for AI coding agents](/en/guides/build-with-ai/#background-mode) for more about automatic agent detection and the health endpoint.</ReadMore>

### `--json`

<p><Since v="7.0.0" /></p>
Expand Down
14 changes: 13 additions & 1 deletion src/content/docs/en/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,8 @@ See [the logger API reference](/en/reference/logger-reference/) for more informa
</p>

The entrypoint for the [logger implementation](/en/reference/logger-reference/#the-logger-implementation).
This can be an npm package, or a `URL` pointing to a file in your project:
This can be an npm package, a path relative to your project root, or a `URL` pointing to a
file in your project:

```js title="astro.config.mjs"
import { defineConfig } from 'astro/config';
Expand Down Expand Up @@ -1480,6 +1481,7 @@ export default defineConfig({

<p>

**Type:** `object | false`<br />
<Since v="5.7.0" />
</p>

Expand All @@ -1502,6 +1504,16 @@ export default defineConfig({

Session drivers are configured at build time. This means environment variables used in the driver configuration are inlined. You must create your own driver entrypoint to [override the configuration at runtime](/en/guides/sessions/#overriding-the-configuration-at-runtime).

Since Astro v7.2.0, you can opt out of session support by setting the option to `false`. When sessions are disabled, the session runtime is excluded from the SSR bundle, and adapters skip wiring their default session driver. This is useful for serverless and edge runtimes where bundle parse time is sensitive.

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

export default defineConfig({
session: false,
});
```

See [the sessions guide](/en/guides/sessions/) for more information.

### session.driver
Expand Down
Loading
Loading