Skip to content

Commit 8af9ae1

Browse files
sarah11918ArmandPhilippotyanthomasdevopenscriptflorian-lefebvre
authored
5.14.0 minor release docs (#12413)
Co-authored-by: Armand Philippot <[email protected]> Co-authored-by: yanthomasdev <[email protected]> Co-authored-by: Robin Bühler <[email protected]> Co-authored-by: florian-lefebvre <[email protected]> Co-authored-by: ArmandPhilippot <[email protected]> Co-authored-by: Florian Lefebvre <[email protected]> Co-authored-by: Luiz Ferraz <[email protected]>
1 parent 1eb485c commit 8af9ae1

File tree

6 files changed

+156
-13
lines changed

6 files changed

+156
-13
lines changed

astro.sidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export const sidebar = [
151151
'reference/experimental-flags/heading-id-compat',
152152
'reference/experimental-flags/static-import-meta-env',
153153
'reference/experimental-flags/chrome-devtools-workspace',
154+
'reference/experimental-flags/fail-on-prerender-conflict',
154155
],
155156
}),
156157
'reference/legacy-flags',

src/content/docs/en/guides/images.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,33 @@ import Logo from '../assets/logo.svg';
433433
<Logo width={64} height={64} fill="currentColor" />
434434
```
435435

436+
#### `SvgComponent` Type
437+
438+
<Since v="5.14.0" />
439+
440+
You can also enforce type safety for your `.svg` assets using the `SvgComponent` type:
441+
442+
```astro title="src/components/Logo.astro"
443+
---
444+
import type { SvgComponent } from "astro/types";
445+
import HomeIcon from './Home.svg'
446+
447+
interface Link {
448+
url: string
449+
text: string
450+
icon: SvgComponent
451+
}
452+
453+
const links: Link[] = [
454+
{
455+
url: '/',
456+
text: 'Home',
457+
icon: HomeIcon
458+
}
459+
]
460+
---
461+
```
462+
436463
### Creating custom image components
437464

438465
You can create a custom, reusable image component by wrapping the `<Image />` or `<Picture/>` component in another Astro component. This allows you to set default attributes and styles only once.

src/content/docs/en/guides/integrations-guide/react.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,30 @@ To use your first React component in Astro, head to our [UI framework documentat
115115
* 💧 client-side hydration options, and
116116
* 🤝 opportunities to mix and nest frameworks together
117117

118-
## Integrate Actions with `useActionState()` (experimental)
118+
## Integrate Actions with `useActionState()`
119119

120-
The `@astrojs/react` integration provides two experimental functions for use with [Astro Actions][astro-actions]: `experimental_withState()` and `experimental_getActionState()`.
120+
The `@astrojs/react` integration provides two functions for use with [Astro Actions][astro-actions]: `withState()` and `getActionState()`.
121121

122122
These are used with [React's useActionState() hook](https://react.dev/reference/react/useActionState) to read and update client-side state when triggering actions during form submission.
123123

124-
### `experimental_withState()`
124+
### `withState()`
125125

126126
<p>
127127

128128
**Type:** `(action: FormFn<T>) => (state: T, formData: FormData) => FormFn<T>`<br />
129-
<Since v="4.3.2" />
129+
<Since v="4.4.0" pkg="@astrojs/react" />
130130
</p>
131131

132-
You can pass `experimental_withState()` and the action you want to trigger to React's `useActionState()` hook as the form action function. The example below passes a `like` action to increase a counter along with an initial state of `0` likes.
132+
You can pass `withState()` and the action you want to trigger to React's `useActionState()` hook as the form action function. The example below passes a `like` action to increase a counter along with an initial state of `0` likes.
133133

134134
```jsx title="Like.tsx" ins={2,7} "useActionState"
135135
import { actions } from 'astro:actions';
136-
import { experimental_withState } from '@astrojs/react/actions';
136+
import { withState } from '@astrojs/react/actions';
137137
import { useActionState } from "react";
138138

139139
export function Like({ postId }: { postId: string }) {
140140
const [state, action, pending] = useActionState(
141-
experimental_withState(actions.like),
141+
withState(actions.like),
142142
{ data: 0, error: undefined }, // initial likes and errors
143143
);
144144

@@ -151,32 +151,32 @@ export function Like({ postId }: { postId: string }) {
151151
}
152152
```
153153

154-
The `experimental_withState()` function will match the action's types with React's expectations and preserve metadata used for progressive enhancement, allowing it to work even when JavaScript is disabled on the user's device.
154+
The `withState()` function will match the action's types with React's expectations and preserve metadata used for progressive enhancement, allowing it to work even when JavaScript is disabled on the user's device.
155155

156-
### `experimental_getActionState()`
156+
### `getActionState()`
157157

158158
<p>
159159

160160
**Type:** `(context: ActionAPIContext) => Promise<T>`<br />
161-
<Since v="4.3.2" />
161+
<Since v="4.4.0" pkg="@astrojs/react" />
162162
</p>
163163

164-
You can access the state stored by `useActionState()` on the server in your action `handler` with `experimental_getActionState()`. It accepts the [Astro API context](/en/reference/api-reference/#the-context-object), and optionally, you can apply a type to the result.
164+
You can access the state stored by `useActionState()` on the server in your action `handler` with `getActionState()`. It accepts the [Astro API context](/en/reference/api-reference/#the-context-object), and optionally, you can apply a type to the result.
165165

166166
The example below gets the current value of likes from a counter, typed as a number, in order to create an incrementing `like` action:
167167

168168
```ts title="actions.ts" ins={3,11}
169169
import { defineAction, type SafeResult } from 'astro:actions';
170170
import { z } from 'astro:schema';
171-
import { experimental_getActionState } from '@astrojs/react/actions';
171+
import { getActionState } from '@astrojs/react/actions';
172172

173173
export const server = {
174174
like: defineAction({
175175
input: z.object({
176176
postId: z.string(),
177177
}),
178178
handler: async ({ postId }, ctx) => {
179-
const { data: currentLikes = 0, error } = await experimental_getActionState<SafeResult<any, number>>(ctx);
179+
const { data: currentLikes = 0, error } = await getActionState<SafeResult<any, number>>(ctx);
180180

181181
// handle errors
182182
if (error) throw error;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Experimental prerender conflict error
3+
sidebar:
4+
label: Prerender conflict error
5+
i18nReady: true
6+
---
7+
8+
import Since from '~/components/Since.astro'
9+
10+
<p>
11+
12+
**Type:** `boolean`<br />
13+
**Default:** `false`<br />
14+
<Since v="5.14.0" />
15+
</p>
16+
17+
Turns prerender conflict warnings into errors during the build process.
18+
19+
Astro currently warns you during the build about any conflicts between multiple dynamic routes that can result in the same output path. For example `/blog/[slug]` and `/blog/[...all]` both could try to prerender the `/blog/post-1` path. In such cases, Astro renders only the [highest priority route](/en/guides/routing/#route-priority-order) for the conflicting path. This allows your site to build successfully, although you may discover that some pages are rendered by unexpected routes.
20+
21+
With this experimental flag set, the build will instead fail immediately with an error. This will require you to resolve any routing conflicts immediately, and will ensure that Astro is building your routes as you intend.
22+
23+
To enable this behavior, add the `experimental.failOnPrerenderConflict` feature flag to your Astro config:
24+
25+
```js title="astro.config.mjs" ins={4-6}
26+
import { defineConfig } from "astro/config"
27+
28+
defineConfig({
29+
experimental: {
30+
failOnPrerenderConflict: true,
31+
},
32+
});
33+
```
34+
35+
## Usage
36+
37+
After enabling this flag, you may encounter errors about conflicting prerendered routes when you attempt to build your project. If this happens, you will need to update one or more of your [dynamic routes](/en/guides/routing/#dynamic-routes) to avoid ambiguous routing.

src/content/docs/en/reference/experimental-flags/fonts.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,49 @@ import { Font } from 'astro:assets';
325325
<Font cssVariable="--font-roboto" preload />
326326
```
327327

328+
## Accessing font data programmatically
329+
330+
The `getFontData()` function is intended for retrieving lower-level font family data programmatically, for example, in an [API Route](/en/guides/endpoints/#server-endpoints-api-routes) or to generate your own meta tags.
331+
332+
### `getFontData()`
333+
<p>
334+
335+
**Type:** `(cssVariable: CssVariable) => FontData[]`<br />
336+
<Since v="5.14.0" />
337+
</p>
338+
339+
Returns an array of `FontData` objects for the provided [`cssVariable`](#cssvariable-1), which contains `src`, `weight` and `style`.
340+
341+
The following example uses `getFontData()` to get the font buffer from the URL when using [satori](https://github.com/vercel/satori) to generate OpenGraph images:
342+
343+
```tsx title="src/pages/og.png.ts" "getFontData(\"--font-roboto\")" "data[0].src[0].url"
344+
import type{ APIRoute } from "astro"
345+
import { getFontData } from "astro:assets"
346+
import satori from "satori"
347+
348+
export const GET: APIRoute = (context) => {
349+
const data = getFontData("--font-roboto")
350+
351+
const svg = await satori(
352+
<div style={{ color: "black" }}>hello, world</div>,
353+
{
354+
width: 600,
355+
height: 400,
356+
fonts: [
357+
{
358+
name: "Roboto",
359+
data: await fetch(new URL(data[0].src[0].url, context.url.origin)).then(res => res.arrayBuffer()),
360+
weight: 400,
361+
style: "normal",
362+
},
363+
],
364+
},
365+
)
366+
367+
// ...
368+
}
369+
```
370+
328371
## Font configuration reference
329372

330373
All properties of your fonts must be configured in the Astro config. Some properties are common to both remote and local fonts, and other properties are available depending on your chosen font provider.

src/content/docs/en/reference/routing-reference.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,41 @@ const { post } = Astro.props;
170170
<h1>{id}: {post.name}</h1>
171171
```
172172

173+
### `routePattern`
174+
175+
<p>
176+
177+
**Type:** `string` <br />
178+
<Since v="5.14.0" />
179+
</p>
180+
181+
A property available in [`getStaticPaths()`](#getstaticpaths) options to access the current [`routePattern`](/en/reference/api-reference/#routepattern) as a string.
182+
183+
This provides data from the [Astro render context](/en/reference/api-reference/) that would not otherwise be available within the scope of `getStaticPaths()` and can be useful to calculate the `params` and `props` for each page route.
184+
185+
`routePattern` always reflects the original dynamic segment definition in the file path (e.g. `/[...locale]/[files]/[slug]`), unlike `params`, which are explicit values for a page (e.g. `/fr/fichiers/article-1/`).
186+
187+
The following example shows how to localize your route segments and return an array of static paths by passing `routePattern` to a custom `getLocalizedData()` helper function. The [params](https://github.com/en/reference/routing-reference/#params) object will be set with explicit values for each route segment: `locale`, `files`, and `slug`. Then, these values will be used to generate the routes and can be used in your page template via `Astro.params`.
188+
189+
190+
```astro title="src/pages/[...locale]/[files]/[slug].astro" "routePattern" "getLocalizedData"
191+
---
192+
import { getLocalizedData } from "../../../utils/i18n";
193+
194+
export async function getStaticPaths({ routePattern }) {
195+
const response = await fetch('...');
196+
const data = await response.json();
197+
198+
console.log(routePattern); // [...locale]/[files]/[slug]
199+
200+
// Call your custom helper with `routePattern` to generate the static paths
201+
return data.flatMap((file) => getLocalizedData(file, routePattern));
202+
}
203+
204+
const { locale, files, slug } = Astro.params;
205+
---
206+
```
207+
173208
### `paginate()`
174209

175210
<p>

0 commit comments

Comments
 (0)