@astrojs/react
๐ฟ Minor Changes
- #12678
97c9265Thanks @bskimball! - Add React 19 stable to peer dependencies
- #12678
โจ Major Changes
๐ฟ Minor Changes
๐ฟ Minor Changes
- #12510
14feaf3Thanks @bholmesdev! - Changes the generated URL query param from_astroActionto_actionwhen submitting a form using Actions. This avoids leaking the framework name into the URL bar, which may be considered a security issue.
- #12510
๐ Patch Changes
-
#11571
1c3265aThanks @bholmesdev! - BREAKING CHANGE to the experimental Actions API only. Install the latest@astrojs/reactintegration as well if youโre using React 19 features.Make
.safe()the default return value for actions. This means{ data, error }will be returned when calling an action directly. If you prefer to get the data while allowing errors to throw, chain the.orThrow()modifier.import { actions } from 'astro:actions';// Beforeconst { data, error } = await actions.like.safe();// Afterconst { data, error } = await actions.like();// Beforeconst newLikes = await actions.like();// Afterconst newLikes = await actions.like.orThrow();To migrate your existing action calls:
- Remove
.safefrom existing safe action calls - Add
.orThrowto existing unsafe action calls
- Remove
-
#11570
84189b6Thanks @bholmesdev! - BREAKING CHANGE to the experimental Actions API only. Install the latest@astrojs/reactintegration as well if youโre using React 19 features.Updates the Astro Actions fallback to support
action={actions.name}instead of usinggetActionProps().This will submit a form to the server in zero-JS scenarios using a search parameter:---import { actions } from 'astro:actions';---<form action={actions.logOut}><!--output: action="?_astroAction=logOut"--><button>Log Out</button></form>You may also construct form action URLs using string concatenation, or by using the
URL()constructor, with the an actionโs.queryStringproperty:---import { actions } from 'astro:actions';const confirmationUrl = new URL('/confirmation', Astro.url);confirmationUrl.search = actions.queryString;---<form method="POST" action={confirmationUrl.pathname}><button>Submit</button></form>getActionProps()is now deprecated. To use the new fallback pattern, remove thegetActionProps()input from your form and pass your action function to the formactionattribute:---import {actions,getActionProps,} from 'astro:actions';---<form method="POST" action={actions.logOut}><form method="POST"><input {...getActionProps(actions.logOut)} /><button>Log Out</button></form>
-
๐ฟ Minor Changes
-
#11234
4385bf7Thanks @ematipico! - Adds a new function calledaddServerRendererto the Container API. Use this function to manually store renderers inside the instance of your container.This new function should be preferred when using the Container API in environments like on-demand pages:
import type { APIRoute } from 'astro';import { experimental_AstroContainer } from 'astro/container';import reactRenderer from '@astrojs/react/server.js';import vueRenderer from '@astrojs/vue/server.js';import ReactComponent from '../components/button.jsx';import VueComponent from '../components/button.vue';// MDX runtime is contained inside the Astro coreimport mdxRenderer from 'astro/jsx/server.js';// In case you need to import a custom rendererimport customRenderer from '../renderers/customRenderer.js';export const GET: APIRoute = async (ctx) => {const container = await experimental_AstroContainer.create();container.addServerRenderer({ renderer: reactRenderer });container.addServerRenderer({ renderer: vueRenderer });container.addServerRenderer({ renderer: customRenderer });// You can pass a custom name toocontainer.addServerRenderer({name: 'customRenderer',renderer: customRenderer,});const vueComponent = await container.renderToString(VueComponent);return await container.renderToResponse(Component);};
-
๐ฟ Minor Changes
-
#11144
803dd80Thanks @ematipico! - The integration now exposes a function calledgetContainerRenderer, that can be used inside the Container APIs to load the relative renderer.import { experimental_AstroContainer as AstroContainer } from 'astro/container';import ReactWrapper from '../src/components/ReactWrapper.astro';import { loadRenderers } from 'astro:container';import { getContainerRenderer } from '@astrojs/react';test('ReactWrapper with react renderer', async () => {const renderers = await loadRenderers([getContainerRenderer()]);const container = await AstroContainer.create({renderers,});const result = await container.renderToString(ReactWrapper);expect(result).toContain('Counter');expect(result).toContain('Count: <!-- -->5');});
-
๐ฟ Minor Changes
-
#11071
8ca7c73Thanks @bholmesdev! - Adds two new functionsexperimental_getActionState()andexperimental_withState()to support the React 19useActionState()hook when using Astro Actions. This introduces progressive enhancement when calling an Action with thewithState()utility.This example calls a
likeaction that accepts apostIdand returns the number of likes. Pass this action to theexperimental_withState()function to apply progressive enhancement info, and apply touseActionState()to track the result:import { actions } from 'astro:actions';import { experimental_withState } from '@astrojs/react/actions';export function Like({ postId }: { postId: string }) {const [state, action, pending] = useActionState(experimental_withState(actions.like),0 // initial likes);return (<form action={action}><input type="hidden" name="postId" value={postId} /><button disabled={pending}>{state} โค๏ธ</button></form>);}You can also access the state stored by
useActionState()from your actionhandler. Callexperimental_getActionState()with the API context, and optionally apply a type to the result:import { defineAction, z } from 'astro:actions';import { experimental_getActionState } from '@astrojs/react/actions';export const server = {like: defineAction({input: z.object({postId: z.string(),}),handler: async ({ postId }, ctx) => {const currentLikes = experimental_getActionState<number>(ctx);// write to databasereturn currentLikes + 1;},}),};
-
๐ Patch Changes
- #10855
f6bddd3Thanks @lamATnginx! - Fix Redoc usage in React integration
- #10855
๐ฟ Minor Changes
-
#10689
683d51a5eecafbbfbfed3910a3f1fbf0b3531b99Thanks @ematipico! - Deprecate support for versions of Node.js older thanv18.17.1for Node.js 18, older thanv20.0.3for Node.js 20, and the complete Node.js v19 release line.This change is in line with Astroโs Node.js support policy.
-
๐ฟ Minor Changes
- #10675
14f1d49a10541fecc4c10def8a094322442ccf23Thanks @fightingcat! - Expose Babel config for @astro/react.
- #10675
๐ Patch Changes
- #10654
195f51f82a44df32be73865949aabee0d46ffe61Thanks @matthewp! - Mark @material-tailwind/react as noExternal
- #10654