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

4.5 minor release docs #7250

Merged
merged 11 commits into from
Mar 11, 2024
99 changes: 84 additions & 15 deletions src/content/docs/en/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,18 @@ Specifies the directory in the build output where Astro-generated assets (bundle

<p>

**Type:** `string`<br />
**Type:** `string | Record.<string, string>`<br />
**Default:** `undefined`<br />
<Since v="2.2.0" />
</p>

Specifies the prefix for Astro-generated asset links. This can be used if assets are served from a different domain than the current site.

For example, if this is set to `https://cdn.example.com`, assets will be fetched from `https://cdn.example.com/_astro/...` (regardless of the `base` option).
You would need to upload the files in `./dist/_astro/` to `https://cdn.example.com/_astro/` to serve the assets.
The process varies depending on how the third-party domain is hosted.
This requires uploading the assets in your local `./dist/_astro` folder to a corresponding `/_astro/` folder on the remote domain.
To rename the `_astro` path, specify a new directory in `build.assets`.

To fetch all assets uploaded to the same domain (e.g. `https://cdn.example.com/_astro/...`), set `assetsPrefix` to the root domain as a string (regardless of your `base` configuration):

```js
{
build: {
Expand All @@ -512,6 +512,24 @@ To rename the `_astro` path, specify a new directory in `build.assets`.
}
```

**Added in:** `astro@4.5.0`

You can also pass an object to `assetsPrefix` to specify a different domain for each file type.
In this case, a `fallback` property is required and will be used by default for any other files.

```js
{
build: {
assetsPrefix: {
'js': 'https://js.cdn.example.com',
'mjs': 'https://js.cdn.example.com',
'css': 'https://css.cdn.example.com',
'fallback': 'https://cdn.example.com'
}
}
}
```

### build.serverEntry

<p>
Expand Down Expand Up @@ -890,7 +908,7 @@ Shiki configuration options. See [the Markdown configuration docs](/en/guides/ma
</p>

Which syntax highlighter to use, if any.
- `shiki` - use the [Shiki](https://github.com/shikijs/shiki) highlighter
- `shiki` - use the [Shiki](https://shiki.style) highlighter
- `prism` - use the [Prism](https://prismjs.com/) highlighter
- `false` - do not apply syntax highlighting.

Expand Down Expand Up @@ -1127,25 +1145,29 @@ in the latest version, so that you can continue to upgrade and take advantage of
Astro offers experimental flags to give users early access to new features.
These flags are not guaranteed to be stable.

### experimental.optimizeHoistedScript
### experimental.directRenderScript

<p>

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

Prevents unused components' scripts from being included in a page unexpectedly.
The optimization is best-effort and may inversely miss including the used scripts. Make sure to double-check your built pages
before publishing.
Enable hoisted script analysis optimization by adding the experimental flag:
Enables a more reliable strategy to prevent scripts from being executed in pages where they are not used.

Scripts will directly render as declared in Astro files (including existing features like TypeScript, importing `node_modules`,
and deduplicating scripts). You can also now conditionally render scripts in your Astro file.
However, this means scripts are no longer hoisted to the `<head>` and multiple scripts on a page are no longer bundled together.
If you enable this option, you should check that all your `<script>` tags behave as expected.

This option will be enabled by default in Astro 5.0.

```js
{
experimental: {
optimizeHoistedScript: true,
},
experimental: {
directRenderScript: true,
},
}
```

Expand All @@ -1168,6 +1190,53 @@ Enables a persistent cache for content collections when building in static mode.
}
```

### experimental.contentCollectionJsonSchema

<p>

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

This feature will auto-generate a JSON schema for content collections of `type: 'data'` which can be used as the `$schema` value for TypeScript-style autocompletion/hints in tools like VSCode.

To enable this feature, add the experimental flag:

```diff
import { defineConfig } from 'astro/config';
export default defineConfig({
experimental: {
+ contentCollectionJsonSchema: true
}
});
```

This experimental implementation requires you to manually reference the schema in each data entry file of the collection:

```diff
// src/content/test/entry.json
{
+ "$schema": "../../../.astro/collections/test.schema.json",
"test": "test"
}
```

Alternatively, you can set this in your [VSCode `json.schemas` settings](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings):

```diff
"json.schemas": [
{
"fileMatch": [
"/src/content/test/**"
],
"url": "../../../.astro/collections/test.schema.json"
}
]
```

Note that this initial implementation uses a library with [known issues for advanced Zod schemas](https://github.com/StefanTerdell/zod-to-json-schema#known-issues), so you may wish to consult these limitations before enabling the experimental flag.

### experimental.clientPrerender

<p>
Expand All @@ -1179,7 +1248,7 @@ Enables a persistent cache for content collections when building in static mode.

Enables pre-rendering your prefetched pages on the client in supported browsers.

This feature uses the experimental [Speculation Rules Web API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) and overrides the default `prefetch` behavior globally to prerender links on the client.
This feature uses the experimental [Speculation Rules Web API](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API) and enhances the default `prefetch` behavior globally to prerender links on the client.
You may wish to review the [possible risks when prerendering on the client](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API#unsafe_prefetching) before enabling this feature.

Enable client side prerendering in your `astro.config.mjs` along with any desired `prefetch` configuration options:
Expand Down
1 change: 1 addition & 0 deletions src/content/docs/en/reference/error-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The following reference is a complete list of the errors you may encounter while
- [**MiddlewareNoDataOrNextCalled**](/en/reference/errors/middleware-no-data-or-next-called/)<br/>The middleware didn't return a `Response`.
- [**MiddlewareNotAResponse**](/en/reference/errors/middleware-not-aresponse/)<br/>The middleware returned something that is not a `Response` object.
- [**LocalsNotAnObject**](/en/reference/errors/locals-not-an-object/)<br/>Value assigned to `locals` is not accepted.
- [**AstroResponseHeadersReassigned**](/en/reference/errors/astro-response-headers-reassigned/)<br/>`Astro.response.headers` must not be reassigned.
- [**MiddlewareCantBeLoaded**](/en/reference/errors/middleware-cant-be-loaded/)<br/>Can't load the middleware.
- [**LocalImageUsedWrongly**](/en/reference/errors/local-image-used-wrongly/)<br/>Local images must be imported.
- [**AstroGlobUsedOutside**](/en/reference/errors/astro-glob-used-outside/)<br/>Astro.glob() used outside of an Astro file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# NOTE: This file is auto-generated from 'scripts/error-docgen.mjs'
# Do not make edits to it directly, they will be overwritten.
# Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
# Translators, please remove this note and the <DontEditWarning/> component.

title: Astro.response.headers must not be reassigned.
i18nReady: true
githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts
---
import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />


> **AstroResponseHeadersReassigned**: Individual headers can be added to and removed from `Astro.response.headers`, but it must not be replaced with another instance of `Headers` altogether.

## What went wrong?
Thrown when a value is being set as the `headers` field on the `ResponseInit` object available as `Astro.response`.



Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import DontEditWarning from '~/components/DontEditWarning.astro'
> **LocalsNotAnObject**: `locals` can only be assigned to an object. Other values like numbers, strings, etc. are not accepted.

## What went wrong?
Thrown in development mode when `locals` is overwritten with something that is not an object
Thrown when `locals` is overwritten with something that is not an object

For example:
```ts
Expand Down
Loading