
🍿 Minor Changes
-
#11729
1c54e63Thanks @ematipico! - Adds a new variantsyncfor theastro:config:setuphook’scommandproperty. This value is set when calling the commandastro sync.If your integration previously relied on knowing how many variants existed for the
commandproperty, you must update your logic to account for this new option. -
#11743
cce0894Thanks @ph1p! - Adds a new, optional propertytimeoutfor theclient:idledirective.This value allows you to specify a maximum time to wait, in milliseconds, before hydrating a UI framework component, even if the page is not yet done with its initial load. This means you can delay hydration for lower-priority UI elements with more control to ensure your element is interactive within a specified time frame.
<ShowHideButton client:idle={{ timeout: 500 }} /> -
#11677
cb356a5Thanks @ematipico! - Adds a new optionfallbackTypetoi18n.routingconfiguration that allows you to control how fallback pages are handled.When
i18n.fallbackis configured, this new routing option controls whether to redirect to the fallback page, or to rewrite the fallback page’s content in place.The
"redirect"option is the default value and matches the current behavior of the existing fallback system.The option
"rewrite"uses the new rewriting system to create fallback pages that render content on the original, requested URL without a browser refresh.For example, the following configuration will generate a page
/fr/index.htmlthat will contain the same HTML rendered by the page/en/index.htmlwhensrc/pages/fr/index.astrodoes not exist.astro.config.mjs export default defineConfig({i18n: {locals: ['en', 'fr'],defaultLocale: 'en',routing: {prefixDefaultLocale: true,fallbackType: 'rewrite',},fallback: {fr: 'en',},},}); -
#11708
62b0d20Thanks @martrapp! - Adds a new objectswapFunctionsto expose the necessary utility functions onastro:transitions/clientthat allow you to build custom swap functions to be used with view transitions.The example below uses these functions to replace Astro’s built-in default
swapfunction with one that only swaps the<main>part of the page:<script>import { swapFunctions } from 'astro:transitions/client';document.addEventListener('astro:before-swap', (e) => { e.swap = () => swapMainOnly(e.newDocument) });function swapMainOnly(doc: Document) {swapFunctions.deselectScripts(doc);swapFunctions.swapRootAttributes(doc);swapFunctions.swapHeadElements(doc);const restoreFocusFunction = swapFunctions.saveFocus();const newMain = doc.querySelector('main');const oldMain = document.querySelector('main');if (newMain && oldMain) {swapFunctions.swapBodyElement(newMain, oldMain);} else {swapFunctions.swapBodyElement(doc.body, document.body);}restoreFocusFunction();};</script>See the view transitions guide for more information about hooking into the
astro:before-swaplifecycle event and adding a custom swap implementation. -
#11843
5b4070eThanks @bholmesdev! - Exposeszfrom the newastro:schemamodule. This is the new recommended import source for all Zod utilities when using Astro Actions.zwill no longer be exposed fromastro:actions. To usezin your actions, import it fromastro:schemainstead:import {defineAction,z,} from 'astro:actions';import { z } from 'astro:schema'; -
#11843
5b4070eThanks @bholmesdev! - The Astro Actions API introduced behind a flag in v4.8.0 is no longer experimental and is available for general use.Astro Actions allow you to define and call backend functions with type-safety, performing data fetching, JSON parsing, and input validation for you.
Actions can be called from client-side components and HTML forms. This gives you to flexibility to build apps using any technology: React, Svelte, HTMX, or just plain Astro components. This example calls a newsletter action and renders the result using an Astro component:
src/pages/newsletter.astro ---import { actions } from 'astro:actions';const result = Astro.getActionResult(actions.newsletter);---{result && !result.error && <p>Thanks for signing up!</p>}<form method="POST" action={actions.newsletter}><input type="email" name="email" /><button>Sign up</button></form>If you were previously using this feature, please remove the experimental flag from your Astro config:
import { defineConfig } from 'astro'export default defineConfig({experimental: {actions: true,}})If you have been waiting for stabilization before using Actions, you can now do so.
For more information and usage examples, see our brand new Actions guide.
🐞 Patch Changes
-
#11677
cb356a5Thanks @ematipico! - Fixes a bug in the logic ofAstro.rewrite()which led to the value forbase, if configured, being automatically prepended to the rewrite URL passed. This was unintended behavior and has been corrected, and Astro now processes the URLs exactly as passed.If you use the
rewrite()function on a project that hasbaseconfigured, you must now prepend the base to your existing rewrite URL:astro.config.mjs export default defineConfig({base: '/blog',});src/middleware.js export function onRequest(ctx, next) {return ctx.rewrite("/about")return ctx.rewrite("/blog/about")} -
#11862
0e35afeThanks @ascorbic! - BREAKING CHANGE to experimental content layer loaders only!Passes
AstroConfiginstead ofAstroSettingsobject to content layer loaders.This will not affect you unless you have created a loader that uses the
settingsobject. If you have, you will need to update your loader to use theconfigobject instead.export default function myLoader() {return {name: 'my-loader'async load({ settings }) {const base = settings.config.base;async load({ config }) {const base = config.base;// ...}}}Other properties of the settings object are private internals, and should not be accessed directly. If you think you need access to other properties, please open an issue to discuss your use case.
-
#11772
6272e6cThanks @bluwy! - Usesmagicastto update the config forastro add -
#11845
440a4beThanks @bluwy! - Replacesexecawithtinyexecinternally -
#11858
8bab233Thanks @ascorbic! - Correctly resolves content layer images when filePath is not set