Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
385 KiB
astro
5.16.4
Patch Changes
-
#14940
2cf79c2Thanks @ematipico! - Fixes a bug where Astro didn't properly combine CSP resources from thecspconfiguration with those added using the runtime API (Astro.csp.insertDirective()) to form grammatically correct CSP headersNow Astro correctly deduplicate CSP resources. For example, if you have a global resource in the configuration file, and then you add a a new one using the runtime APIs.
5.16.3
Patch Changes
-
#14889
4bceeb0Thanks @florian-lefebvre! - Fixes actions types when using specific TypeScript configurations -
#14929
e0f277dThanks @matthewp! - Fixes authentication bypass via double URL encoding in middlewarePrevents attackers from bypassing path-based authentication checks using multi-level URL encoding (e.g.,
/%2561dmininstead of/%61dmin). Pathnames are now validated after decoding to ensure no additional encoding remains.
5.16.2
Patch Changes
-
#14876
b43dc7fThanks @florian-lefebvre! - Fixes a vite warning log during builds when using npm -
#14884
10273e0Thanks @florian-lefebvre! - Fixes a case where setting the status of a page to404in ssr would show an empty page (or404.astropage if provided) instead of using the current page
5.16.1
Patch Changes
-
#14769
b43ee71Thanks @adriandlam! - Fixes an unhandled rejection issue when using Astro with Vercel Workflow DevKit -
#14761
345eb22Thanks @ooga! - Updatesbuttonattributes types to allowcommandandcommandfor -
#14866
65e214bThanks @GameRoMan! - FixesAstro.globto be correctly marked as deprecated -
#14894
1ad9a5bThanks @delucis! - Fixes support for Astro component rendering in Vitest test suites using a “client” environment such ashappy-domorjsdom -
#14782
abed929Thanks @florian-lefebvre! - Improves syncing
5.16.0
Minor Changes
-
#13880
1a2ed01Thanks @azat-io! - Adds experimental SVGO optimization support for SVG assetsAstro now supports automatic SVG optimization using SVGO during build time. This experimental feature helps reduce SVG file sizes while maintaining visual quality, improving your site's performance.
To enable SVG optimization with default settings, add the following to your
astro.config.mjs:import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { svgo: true, }, });To customize optimization, pass a SVGO configuration object:
export default defineConfig({ experimental: { svgo: { plugins: [ 'preset-default', { name: 'removeViewBox', active: false, }, ], }, }, });For more information on enabling and using this feature in your project, see the experimental SVG optimization docs.
-
#14810
2e845feThanks @ascorbic! - Adds a hint for code agents to use the--yesflag to skip prompts when runningastro add -
#14698
f42ff9bThanks @mauriciabad! - Adds theActionInputSchemautility type to automatically infer the TypeScript type of an action's input based on its Zod schemaFor example, this type can be used to retrieve the input type of a form action:
import { type ActionInputSchema, defineAction } from 'astro:actions'; import { z } from 'astro/zod'; const action = defineAction({ accept: 'form', input: z.object({ name: z.string() }), handler: ({ name }) => ({ message: `Welcome, ${name}!` }), }); type Schema = ActionInputSchema<typeof action>; // typeof z.object({ name: z.string() }) type Input = z.input<Schema>; // { name: string } -
#14574
4356485Thanks @jacobdalamb! - Adds new CLI shortcuts available when runningastro preview:o+enter: open the site in your browserq+enter: quit the previewh+enter: print all available shortcuts
Patch Changes
-
#14813
e1dd377Thanks @ematipico! - Removespicocolorsas dependency in favor of the forkpiccolore. -
#14609
d774306Thanks @florian-lefebvre! - Improvesastro info -
#14796
c29a785Thanks @florian-lefebvre! - BREAKING CHANGE to the experimental Fonts API onlyUpdates the default
subsetsto["latin"]Subsets have been a common source of confusion: they caused a lot of files to be downloaded by default. You now have to manually pick extra subsets.
Review your Astro config and update subsets if you need, for example if you need greek characters:
import { defineConfig, fontProviders } from "astro/config" export default defineConfig({ experimental: { fonts: [{ name: "Roboto", cssVariable: "--font-roboto", provider: fontProviders.google(), + subsets: ["latin", "greek"] }] } })
5.15.9
Patch Changes
-
#14786
758a891Thanks @mef! - Add handling of invalid encrypted props and slots in server islands. -
#14783
504958fThanks @florian-lefebvre! - Improves the experimental Fonts API build log to show the number of downloaded files. This can help spotting excessive downloading because of misconfiguration -
#14791
9e9c528Thanks @Princesseuh! - Changes the remote protocol checks for images to require explicit authorization in order to use data URIs.In order to allow data URIs for remote images, you will need to update your
astro.config.mjsfile to include the following configuration:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ images: { remotePatterns: [ { protocol: 'data', }, ], }, }); -
#14787
0f75f6bThanks @matthewp! - Fixes wildcard hostname pattern matching to correctly reject hostnames without dotsPreviously, hostnames like
localhostor other single-part names would incorrectly match patterns like*.example.com. The wildcard matching logic has been corrected to ensure that only valid subdomains matching the pattern are accepted. -
#14776
3537876Thanks @ktym4a! - Fixes the behavior ofpassthroughImageServiceso it does not generate webp. -
Updated dependencies [
9e9c528,0f75f6b]:- @astrojs/internal-helpers@0.7.5
- @astrojs/markdown-remark@6.3.9
5.15.8
Patch Changes
-
#14772
00c579aThanks @matthewp! - Improves the security of Server Islands slots by encrypting them before transmission to the browser, matching the security model used for props. This improves the integrity of slot content and prevents injection attacks, even when component templates don't explicitly support slots.Slots continue to work as expected for normal usage—this change has no breaking changes for legitimate requests.
-
#14771
6f80081Thanks @matthewp! - Fix middleware pathname matching by normalizing URL-encoded pathsMiddleware now receives normalized pathname values, ensuring that encoded paths like
/%61dminare properly decoded to/adminbefore middleware checks. This prevents potential security issues where middleware checks might be bypassed through URL encoding.
5.15.7
Patch Changes
-
#14765
03fb47cThanks @florian-lefebvre! - Fixes a case whereprocess.envwouldn't be properly populated during the build -
#14690
ae7197dThanks @fredriknorlin! - Fixes a bug where Astro's i18n fallback system withfallbackType: 'rewrite'would not generate fallback files for pages whose filename started with a locale key.
5.15.6
Patch Changes
-
#14751
18c55e1Thanks @delucis! - Fixes hydration of client components when running the dev server and using a barrel file that re-exports both Astro and UI framework components. -
#14750
35122c2Thanks @florian-lefebvre! - Updates the experimental Fonts API to log a warning if families with a conflictingcssVariableare provided -
#14737
74c8852Thanks @Arecsu! - Fixes an error when usingtransition:persistwith components that use declarative Shadow DOM. Astro now avoids re-attaching a shadow root if one already exists, preventing"Unable to re-attach to existing ShadowDOM"navigation errors. -
#14750
35122c2Thanks @florian-lefebvre! - Updates the experimental Fonts API to allow for more granular configuration of remote font familiesA font family is defined by a combination of properties such as weights and styles (e.g.
weights: [500, 600]andstyles: ["normal", "bold"]), but you may want to download only certain combinations of these.For greater control over which font files are downloaded, you can specify the same font (ie. with the same
cssVariable,name, andproviderproperties) multiple times with different combinations. Astro will merge the results and download only the required files. For example, it is possible to download normal500and600while downloading only italic500:// astro.config.mjs import { defineConfig, fontProviders } from 'astro/config'; export default defineConfig({ experimental: { fonts: [ { name: 'Roboto', cssVariable: '--roboto', provider: fontProviders.google(), weights: [500, 600], styles: ['normal'], }, { name: 'Roboto', cssVariable: '--roboto', provider: fontProviders.google(), weights: [500], styles: ['italic'], }, ], }, });
5.15.5
Patch Changes
-
#14712
91780cfThanks @florian-lefebvre! - Fixes a case where build'sprocess.envwould be inlined in the server output -
#14713
666d5a7Thanks @florian-lefebvre! - Improves fallbacks generation when using the experimental Fonts API -
#14743
dafbb1bThanks @matthewp! - ImprovesX-Forwardedheader validation to prevent cache poisoning and header injection attacks. Now properly validatesX-Forwarded-Proto,X-Forwarded-Host, andX-Forwarded-Portheaders against configuredallowedDomainspatterns, rejecting malformed or suspicious values. This is especially important when running behind a reverse proxy or load balancer.
5.15.4
Patch Changes
-
#14703
970ac0fThanks @ArmandPhilippot! - Adds missing documentation for some public utilities exported fromastro:i18n. -
#14715
3d55c5dThanks @ascorbic! - Adds support for client hydration ingetContainerRenderer()The
getContainerRenderer()function is exported by Astro framework integrations to simplify the process of rendering framework components when using the experimental Container API inside a Vite or Vitest environment. This update adds the client hydration entrypoint to the returned object, enabling client-side interactivity for components rendered using this function. Previously this required users to manually callcontainer.addClientRenderer()with the appropriate client renderer entrypoint.See the
container-with-vitestdemo for a usage example, and the Container API documentation for more information on using framework components with the experimental Container API. -
#14711
a4d284dThanks @deining! - Fixes typos in documenting our error messages and public APIs. -
#14701
9be54c7Thanks @florian-lefebvre! - Fixes a case where the experimental Fonts API would filter available font files too aggressively, which could prevent the download of woff files when using the google provider
5.15.3
Patch Changes
-
#14627
b368de0Thanks @matthewp! - Fixes skew protection support for images and font URLsAdapter-level query parameters (
assetQueryParams) are now applied to all image and font asset URLs, including:- Dynamic optimized images via
/_imageendpoint - Static optimized image files
- Font preload tags and font requests when using the experimental Fonts API
- Dynamic optimized images via
-
#14631
3ad33f9Thanks @KurtGokhan! - Adds theastro/jsx-dev-runtimeexport as an alias forastro/jsx-runtime
5.15.2
Patch Changes
-
#14623
c5fe295Thanks @delucis! - Fixes a leak of server runtime code when importing SVGs in client-side code. Previously, when importing an SVG file in client code, Astro could end up adding code for rendering SVGs on the server to the client bundle. -
#14621
e3175d9Thanks @GameRoMan! - Updatesviteversion to fix CVE
5.15.1
Patch Changes
- #14612
18552c7Thanks @ematipico! - Fixes a regression introduced in Astro v5.14.7 that caused?urlimports to not work correctly. This release reverts #14142.
5.15.0
Minor Changes
-
#14543
9b3241dThanks @matthewp! - Adds two new adapter configuration optionsassetQueryParamsandinternalFetchHeadersto the Adapter API.Official and community-built adapters can now use
client.assetQueryParamsto specify query parameters that should be appended to asset URLs (CSS, JavaScript, images, fonts, etc.). The query parameters are automatically appended to all generated asset URLs during the build process.Adapters can also use
client.internalFetchHeadersto specify headers that should be included in Astro's internal fetch calls (Actions, View Transitions, Server Islands, Prefetch).This enables features like Netlify's skew protection, which requires the deploy ID to be sent with both internal requests and asset URLs to ensure client and server versions match during deployments.
-
#14489
add4277Thanks @dev-shetty! - Adds a new Copy to Clipboard button to the error overlay stack trace.When an error occurs in dev mode, you can now copy the stack trace with a single click to more easily share it in a bug report, a support thread, or with your favorite LLM.
-
#14564
5e7cebbThanks @florian-lefebvre! - Updatesastro add cloudflareto scaffold more configuration filesRunning
astro add cloudflarewill now emitwrangler.jsoncandpublic/.assetsignore, allowing your Astro project to work out of the box as a worker.
Patch Changes
-
#14591
3e887ecThanks @matthewp! - Adds TypeScript support for thecomponentsprop on MDXContentcomponent when usingawait render(). Developers now get proper IntelliSense and type checking when passing custom components to override default MDX element rendering. -
#14598
7b45c65Thanks @delucis! - Reduces terminal text styling dependency size by switching fromkleurtopicocolors -
#13826
8079482Thanks @florian-lefebvre! - Adds the option to specify in thepreloaddirective which weights, styles, or subsets to preload for a given font family when using the experimental Fonts API:--- import { Font } from 'astro:assets'; --- <Font cssVariable="--font-roboto" preload={[{ subset: 'latin', style: 'normal' }, { weight: '400' }]} />Variable weight font files will be preloaded if any weight within its range is requested. For example, a font file for font weight
100 900will be included when400is specified in apreloadobject.
5.14.8
Patch Changes
- #14590
577d051Thanks @matthewp! - Fixes image path resolution in content layer collections to support bare filenames. Theimage()helper now normalizes bare filenames like"cover.jpg"to relative paths"./cover.jpg"for consistent resolution behavior between markdown frontmatter and JSON content collections.
5.14.7
Patch Changes
-
#14582
7958c6bThanks @florian-lefebvre! - Fixes a regression that caused Actions to throw errors while loading -
#14567
94500bbThanks @matthewp! - Fixes the actions endpoint to return 404 for non-existent actions instead of throwing an unhandled error -
#14566
946fe68Thanks @matthewp! - Fixes handling malformed cookies gracefully by returning the unparsed value instead of throwingWhen a cookie with an invalid value is present (e.g., containing invalid URI sequences),
Astro.cookies.get()now returns the raw cookie value instead of throwing a URIError. This aligns with the behavior of the underlyingcookiepackage and prevents crashes when manually-set or corrupted cookies are encountered. -
#14142
73c5de9Thanks @P4tt4te! - Updates handling of CSS for hydrated client components to prevent duplicates -
#14576
2af62c6Thanks @aprici7y! - Fixes a regression that causedAstro.siteto always beundefinedingetStaticPaths()
5.14.6
Patch Changes
-
#14562
722bba0Thanks @erbierc! - Fixes a bug where the behavior of the "muted" HTML attribute was inconsistent with that of other attributes. -
#14538
51ebe6aThanks @florian-lefebvre! - Improves how Actions are implemented -
#14548
6cdade4Thanks @ascorbic! - Removes support for themaxAgeproperty incacheHintobjects returned by live loaders.⚠️ Breaking change for experimental live content collections only
Feedback showed that this did not make sense to set at the loader level, since the loader does not know how long each individual entry should be cached for.
If your live loader returns cache hints with
maxAge, you need to remove this property:return { entries: [...], cacheHint: { tags: ['my-tag'], - maxAge: 60, lastModified: new Date(), }, };The
cacheHintobject now only supportstagsandlastModifiedproperties. If you want to set the max age for a page, you can set the headers manually:--- Astro.headers.set('cdn-cache-control', 'max-age=3600'); --- -
#14548
6cdade4Thanks @ascorbic! - Adds missingrenderedproperty to experimental live collections entry typeLive collections support a
renderedproperty that allows you to provide pre-rendered HTML for each entry. While this property was documented and implemented, it was missing from the TypeScript types. This could lead to type errors when trying to use it in a TypeScript project.No changes to your project code are necessary. You can continue to use the
renderedproperty as before, and it will no longer produce TypeScript errors.
5.14.5
Patch Changes
-
#14525
4f55781Thanks @penx! - FixesdefineLiveCollection()types -
#14441
62ec8eaThanks @upsuper! - Updates redirect handling to be consistent acrossstaticandserveroutput, aligning with the behavior of other adapters.Previously, the Node.js adapter used default HTML files with meta refresh tags when in
staticoutput. This often resulted in an extra flash of the page on redirect, while also not applying the proper status code for redirections. It's also likely less friendly to search engines.This update ensures that configured redirects are always handled as HTTP redirects regardless of output mode, and the default HTML files for the redirects are no longer generated in
staticoutput. It makes the Node.js adapter more consistent with the other official adapters.No change to your project is required to take advantage of this new adapter functionality. It is not expected to cause any breaking changes. However, if you relied on the previous redirecting behavior, you may need to handle your redirects differently now. Otherwise you should notice smoother redirects, with more accurate HTTP status codes, and may potentially see some SEO gains.
-
#14506
ec3cbe1Thanks @abdo-spices! - Updates the<Font />component so that preload links are generated after the style tag, as recommended by capo.js
5.14.4
Patch Changes
- #14509
7e04cafThanks @ArmandPhilippot! - Fixes an error in the docs that specified an incorrect version for thesecurity.allowedDomainsrelease.
5.14.3
Patch Changes
-
#14505
28b2a1dThanks @matthewp! - FixesCannot set property manifesterror in test utilities by adding a protected setter for the manifest property -
#14235
c4d84bbThanks @toxeeec! - Fixes a bug where the "tap" prefetch strategy worked only on the first clicked link with view transitions enabled
5.14.2
Patch Changes
-
#14459
916f9c2Thanks @florian-lefebvre! - Improves font files URLs in development when using the experimental fonts API by showing the subset if present -
b8ca69bThanks @ascorbic! - Aligns dev image server file base with Vite rules -
#14469
1c090b0Thanks @delucis! - Updatestinyexecdependency -
#14460
008dc75Thanks @florian-lefebvre! - Fixes a case whereastro:config/servervalues typed as URLs would be serialized as strings -
#13730
7260367Thanks @razonyang! - Fixes a bug in i18n, where Astro caused an infinite loop when a locale that doesn't have an index, and Astro falls back to the index of the default locale. -
6ee63bfThanks @matthewp! - Addssecurity.allowedDomainsconfiguration to validateX-Forwarded-Hostheaders in SSRThe
X-Forwarded-Hostheader will now only be trusted if it matches one of the configured allowed host patterns. This prevents host header injection attacks that can lead to cache poisoning and other security vulnerabilities.Configure allowed host patterns to enable
X-Forwarded-Hostsupport:// astro.config.mjs export default defineConfig({ output: 'server', adapter: node(), security: { allowedDomains: [ { hostname: 'example.com' }, { hostname: '*.example.com' }, { hostname: 'cdn.example.com', port: '443' }, ], }, });The patterns support wildcards (
*and**) for flexible hostname matching and can optionally specify protocol and port.Breaking change
Previously,
Astro.urlwould reflect the value of theX-Forwarded-Hostheader. While this header is commonly used by reverse proxies like Nginx to communicate the original host, it can be sent by any client, potentially allowing malicious actors to poison caches with incorrect URLs.If you were relying on
X-Forwarded-Hostsupport, addsecurity.allowedDomainsto your configuration to restore this functionality securely. WhenallowedDomainsis not configured,X-Forwarded-Hostheaders are now ignored by default. -
#14488
badc929Thanks @olcanebrem! - Fixes a case where styles on the custom 500 error page would not be included -
#14487
1e5b72cThanks @florian-lefebvre! - Fixes a case where the URLs generated by the experimental Fonts API would be incorrect in dev -
#14475
ae034aeThanks @florian-lefebvre! - Warns if the font family name is not supported by the provider when using the experimental fonts API -
#14468
2f2a5daThanks @delucis! - Updates@capsizecss/unpackdependency -
Updated dependencies [
b8ca69b]:- @astrojs/internal-helpers@0.7.4
- @astrojs/markdown-remark@6.3.8
5.14.1
Patch Changes
- #14440
a3e16abThanks @florian-lefebvre! - Fixes a case where the URLs generated by the experimental Fonts API would be incorrect in dev
5.14.0
Minor Changes
-
#13520
a31edb8Thanks @openscript! - Adds a new propertyroutePatternavailable toGetStaticPathsOptionsThis provides the original, dynamic segment definition in a routing file path (e.g.
/[...locale]/[files]/[slug]) from the Astro render context that would not otherwise be available within the scope ofgetStaticPaths(). This can be useful to calculate theparamsandpropsfor each page route.For example, you can now localize your route segments and return an array of static paths by passing
routePatternto a customgetLocalizedData()helper function. Theparamsobject will be set with explicit values for each route segment (e.g.locale,files, andslug). Then, these values will be used to generate the routes and can be used in your page template viaAstro.params.--- // src/pages/[...locale]/[files]/[slug].astro import { getLocalizedData } from '../../../utils/i18n'; export async function getStaticPaths({ routePattern }) { const response = await fetch('...'); const data = await response.json(); console.log(routePattern); // [...locale]/[files]/[slug] // Call your custom helper with `routePattern` to generate the static paths return data.flatMap((file) => getLocalizedData(file, routePattern)); } const { locale, files, slug } = Astro.params; ---For more information about this advanced routing pattern, see Astro's routing reference.
-
#13651
dcfbd8cThanks @ADTC! - Adds a newSvgComponenttypeYou can now more easily enforce type safety for your
.svgassets by directly importingSVGComponentfromastro/types:--- // src/components/Logo.astro import type { SvgComponent } from 'astro/types'; import HomeIcon from './Home.svg'; interface Link { url: string; text: string; icon: SvgComponent; } const links: Link[] = [ { url: '/', text: 'Home', icon: HomeIcon, }, ]; --- -
#14206
16a23e2Thanks @Fryuni! - Warn on prerendered routes collision.Previously, when two dynamic routes
/[foo]and/[bar]returned values on theirgetStaticPathsthat resulted in the same final path, only one of the routes would be rendered while the other would be silently ignored. Now, when this happens, a warning will be displayed explaining which routes collided and on which path.Additionally, a new experimental flag
failOnPrerenderConflictcan be used to fail the build when such a collision occurs.
Patch Changes
-
#13811
69572c0Thanks @florian-lefebvre! - Adds a newgetFontData()method to retrieve lower-level font family data programmatically when using the experimental Fonts APIThe
getFontData()helper function fromastro:assetsprovides access to font family data for use outside of Astro. This can then be used in an API Route or to generate your own meta tags.import { getFontData } from 'astro:assets'; const data = getFontData('--font-roboto');For example,
getFontData()can get the font buffer from the URL when using satori to generate OpenGraph images:// src/pages/og.png.ts import type { APIRoute } from 'astro'; import { getFontData } from 'astro:assets'; import satori from 'satori'; export const GET: APIRoute = (context) => { const data = getFontData('--font-roboto'); const svg = await satori(<div style={{ color: 'black' }}>hello, world</div>, { width: 600, height: 400, fonts: [ { name: 'Roboto', data: await fetch(new URL(data[0].src[0].url, context.url.origin)).then((res) => res.arrayBuffer(), ), weight: 400, style: 'normal', }, ], }); // ... };See the experimental Fonts API documentation for more information.
5.13.11
Patch Changes
-
#14409
250a595Thanks @louisescher! - Fixes an issue whereastro infowould log errors to console in certain cases. -
#14398
a7df80dThanks @idawnlight! - Fixes an unsatisfiable type definition when callingaddServerRendereron an experimental container instance -
#13747
120866fThanks @jp-knj! - Adds automatic request signal abortion when the underlying socket closes in the Node.js adapterThe Node.js adapter now automatically aborts the
request.signalwhen the client connection is terminated. This enables better resource management and allows applications to properly handle client disconnections through the standardAbortSignalAPI. -
#14428
32a8acbThanks @drfuzzyness! - Force sharpService to return a Uint8Array if Sharp returns a SharedArrayBuffer -
#14411
a601186Thanks @GameRoMan! - Fixes relative links to docs that could not be opened in the editor.
5.13.10
Patch Changes
- Updated dependencies [
1e2499e]:- @astrojs/internal-helpers@0.7.3
- @astrojs/markdown-remark@6.3.7
5.13.9
Patch Changes
- #14402
54dcd04Thanks @FredKSchott! - Removes warning that caused unexpected console spam when using Bun
5.13.8
Patch Changes
-
#14300
bd4a70bThanks @louisescher! - Adds Vite version & integration versions to output ofastro info -
#14341
f75fd99Thanks @delucis! - Fixes support for declarative Shadow DOM when using the<ClientRouter>component -
#14350
f59581fThanks @ascorbic! - Improves error reporting for content collections by adding logging for configuration errors that had previously been silently ignored. Also adds a new error that is thrown if a live collection is used incontent.config.tsrather thanlive.config.ts. -
#14343
13f7d36Thanks @florian-lefebvre! - Fixes a regression in non node runtimes
5.13.7
Patch Changes
-
#14330
72e14abThanks @ascorbic! - Removes pinned package that is no longer needed. -
#14335
17c7b03Thanks @florian-lefebvre! - Bumpssharpminimal version to0.34.0
5.13.6
Patch Changes
-
#14294
e005855Thanks @martrapp! - Restores the ability to use Google AnalyticsHistory change triggerwith the<ClientRouter />. -
#14326
c24a8f4Thanks @jsparkdev! - Updatesviteversion to fix CVE -
#14108
218e070Thanks @JusticeMatthew! - Updates dynamic route split regex to avoid infinite retries/exponential complexity -
#14327
c1033beThanks @ascorbic! - Pins simple-swizzle to avoid compromised version
5.13.5
Patch Changes
-
#14286
09c5db3Thanks @ematipico! - BREAKING CHANGES only to the experimental CSP featureThe following runtime APIs of the
Astroglobal have been renamed:Astro.insertDirectivetoAstro.csp.insertDirectiveAstro.insertStyleResourcetoAstro.csp.insertStyleResourceAstro.insertStyleHashtoAstro.csp.insertStyleHashAstro.insertScriptResourcetoAstro.csp.insertScriptResourceAstro.insertScriptHashtoAstro.csp.insertScriptHash
The following runtime APIs of the
APIContexthave been renamed:ctx.insertDirectivetoctx.csp.insertDirectivectx.insertStyleResourcetoctx.csp.insertStyleResourcectx.insertStyleHashtoctx.csp.insertStyleHashctx.insertScriptResourcetoctx.csp.insertScriptResourcectx.insertScriptHashtoctx.csp.insertScriptHash
-
#14283
3224637Thanks @ematipico! - Fixes an issue where CSP headers were incorrectly injected in the development server. -
#14275
3e2f20dThanks @florian-lefebvre! - Adds support for experimental CSP when using experimental fontsExperimental fonts now integrate well with experimental CSP by injecting hashes for the styles it generates, as well as
font-srcdirectives.No action is required to benefit from it.
-
#14280
4b9fb73Thanks @ascorbic! - Fixes a bug that caused cookies to not be correctly set when using middleware sequences -
#14276
77281c4Thanks @ArmandPhilippot! - Adds a missing export forresolveSrc, a documented image services utility.
5.13.4
Patch Changes
-
#14260
86a1e40Thanks @jp-knj! - FixesAstro.url.pathnameto respecttrailingSlash: 'never'configuration when using a base path. Previously, the root path with a base would incorrectly return/base/instead of/basewhentrailingSlashwas set to 'never'. -
#14248
e81c4bdThanks @julesyoungberg! - Fixes a bug where actions named 'apply' do not work due to being a function prototype method.
5.13.3
Patch Changes
-
#14239
d7d93e1Thanks @wtchnm! - Fixes a bug where the types for the live content collections were not being generated correctly in dev mode -
#14221
eadc9ddThanks @delucis! - Fixes JSON schema support for content collections using thefile()loader -
#14229
1a9107aThanks @jonmichaeldarby! - EnsuresAstro.currentLocalereturns the correct locale during SSG for pages that use a locale param (such as[locale].astroor[locale]/index.astro, which produce[locale].html)
5.13.2
Patch Changes
-
4d16de7Thanks @ematipico! - Improves the detection of remote paths in the_imageendpoint. Nowhrefparameters that start with//are considered remote paths. -
Updated dependencies [
4d16de7]:- @astrojs/internal-helpers@0.7.2
- @astrojs/markdown-remark@6.3.6
5.13.1
Patch Changes
5.13.0
Minor Changes
-
#14173
39911b8Thanks @florian-lefebvre! - Adds an experimental flagstaticImportMetaEnvto disable the replacement ofimport.meta.envvalues withprocess.envcalls and their coercion of environment variable values. This supersedes therawEnvValuesexperimental flag, which is now removed.Astro allows you to configure a type-safe schema for your environment variables, and converts variables imported via
astro:envinto the expected type. This is the recommended way to use environment variables in Astro, as it allows you to easily see and manage whether your variables are public or secret, available on the client or only on the server at build time, and the data type of your values.However, you can still access environment variables through
process.envandimport.meta.envdirectly when needed. This was the only way to use environment variables in Astro beforeastro:envwas added in Astro 5.0, and Astro's default handling ofimport.meta.envincludes some logic that was only needed for earlier versions of Astro.The
experimental.staticImportMetaEnvflag updates the behavior ofimport.meta.envto align with Vite's handling of environment variables and for better ease of use with Astro's current implementations and features. This will become the default behavior in Astro 6.0, and this early preview is introduced as an experimental feature.Currently, non-public
import.meta.envenvironment variables are replaced by a reference toprocess.env. Additionally, Astro may also convert the value type of your environment variables used throughimport.meta.env, which can prevent access to some values such as the strings"true"(which is converted to a boolean value), and"1"(which is converted to a number).The
experimental.staticImportMetaEnvflag simplifies Astro's default behavior, making it easier to understand and use. Astro will no longer replace anyimport.meta.envenvironment variables with aprocess.envcall, nor will it coerce values.To enable this feature, add the experimental flag in your Astro config and remove
rawEnvValuesif it was enabled:// astro.config.mjs import { defineConfig } from "astro/config"; export default defineConfig({ + experimental: { + staticImportMetaEnv: true - rawEnvValues: false + } });Updating your project
If you were relying on Astro's default coercion, you may need to update your project code to apply it manually:
// src/components/MyComponent.astro - const enabled: boolean = import.meta.env.ENABLED; + const enabled: boolean = import.meta.env.ENABLED === "true";If you were relying on the transformation into
process.envcalls, you may need to update your project code to apply it manually:// src/components/MyComponent.astro - const enabled: boolean = import.meta.env.DB_PASSWORD; + const enabled: boolean = process.env.DB_PASSWORD;You may also need to update types:
// src/env.d.ts interface ImportMetaEnv { readonly PUBLIC_POKEAPI: string; - readonly DB_PASSWORD: string; - readonly ENABLED: boolean; + readonly ENABLED: string; } interface ImportMeta { readonly env: ImportMetaEnv; } + namespace NodeJS { + interface ProcessEnv { + DB_PASSWORD: string; + } + }See the experimental static
import.meta.envdocumentation for more information about this feature. You can learn more about using environment variables in Astro, includingastro:env, in the environment variables documentation. -
#14122
41ed3acThanks @ascorbic! - Adds experimental support for automatic Chrome DevTools workspace foldersThis feature allows you to edit files directly in the browser and have those changes reflected in your local file system via a connected workspace folder. This allows you to apply edits such as CSS tweaks without leaving your browser tab!
With this feature enabled, the Astro dev server will automatically configure a Chrome DevTools workspace for your project. Your project will then appear as a workspace source, ready to connect. Then, changes that you make in the "Sources" panel are automatically saved to your project source code.
To enable this feature, add the experimental flag
chromeDevtoolsWorkspaceto your Astro config:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { chromeDevtoolsWorkspace: true, }, });See the experimental Chrome DevTools workspace feature documentation for more information.
5.12.9
Patch Changes
-
#14020
9518975Thanks @jp-knj and @asieradzk! - Prevent double-prefixed redirect paths when using fallback and redirectToDefaultLocale togetherFixes an issue where i18n fallback routes would generate double-prefixed paths (e.g.,
/es/es/test/item1/) whenfallbackandredirectToDefaultLocaleconfigurations were used together. The fix adds proper checks to prevent double prefixing in route generation. -
#14199
3e4cb8eThanks @ascorbic! - Fixes a bug that prevented HMR from working with inline styles
5.12.8
Patch Changes
-
0567fb7Thanks @ascorbic! - Adds//to list of internal path prefixes that do not have automated trailing slash handling -
#13894
b36e72fThanks @florian-lefebvre! - Removes Astro Studio commands from the CLI help -
Updated dependencies [
0567fb7]:- @astrojs/internal-helpers@0.7.1
- @astrojs/markdown-remark@6.3.5
5.12.7
Patch Changes
-
#14169
f4e8889Thanks @ascorbic! - Skips trailing slash handling for paths that start with/.. -
#14170
34e6b3aThanks @ematipico! - Fixes an issue where static redirects couldn't correctly generate a redirect when the destination is a prerendered route, and theoutputis set to"server". -
#14169
f4e8889Thanks @ascorbic! - Fixes a bug that prevented images from being displayed in dev when using the Netlify adapter withtrailingSlashset toalways -
Updated dependencies [
f4e8889]:- @astrojs/internal-helpers@0.7.0
- @astrojs/markdown-remark@6.3.4
5.12.6
Patch Changes
-
#14153
29e9283Thanks @jp-knj! - Fixes a regression introduced by a recent optimisation of how SVG images are emitted during the build. -
#14156
592f08dThanks @TheOtterlord! - Fix the client router not submitting forms if the active URL contained a hash -
#14160
d2e25c6Thanks @ascorbic! - Fixes a bug that meant some remote image URLs could cause invalid filenames to be used for processed images -
#14167
62bd071Thanks @ascorbic! - Fixes a bug that prevented destroyed sessions from being deleted from storage unless the session had been loaded
5.12.5
Patch Changes
-
#14059
19f53ebThanks @benosmac! - Fixes a bug in i18n implementation, where Astro didn't emit the correct pages whenfallbackis enabled, and a locale uses a catch-all route, e.g.src/pages/es/[...catchAll].astro -
#14155
31822c3Thanks @ascorbic! - Fixes a bug that caused an error "serverEntrypointModule[_start] is not a function" in some adapters
5.12.4
Patch Changes
-
#14031
e9206c1Thanks @jp-knj! - Optimized the build pipeline for SVG images. Now, Astro doesn't reprocess images that have already been processed. -
#14132
976879aThanks @ematipico! - Fixes a bug where the propertyAstro.routePattern/context.routePatternwasn't updated when using a rewrite via middleware. -
#14131
aafc4d7Thanks @florian-lefebvre! - Fixes a case where an error occurring in a middleware would show the dev overlay instead of the custom500.astropage -
#14127
2309adaThanks @florian-lefebvre! - Upgrades zod -
#14134
186c201Thanks @ascorbic! - Throws a more helpful error in dev if trying to use a server island without an adapter -
#14129
3572d85Thanks @ematipico! - Fixes a bug where the CSP headers was incorrectly added to a page when using an adapter.
5.12.3
Patch Changes
-
#14119
14807a4Thanks @ascorbic! - Fixes a bug that caused builds to fail if a client directive was mistakenly added to an Astro component -
#14001
4b03d9cThanks @dnek! - Fixes an issue wheregetImage()assigned the resized base URL to the srcset URL ofImageTransform, which matched the width, height, and format of the original image.
5.12.2
Patch Changes
-
#14071
d2cb35dThanks @Grisoly! - Exposes theCodecomponentlangprop type:import type { CodeLanguage } from 'astro'; -
#14111
5452ee6Thanks @ascorbic! - Fixes a bug that prevented "key" from being used as a prop for Astro components in MDX -
#14106
b5b39e4Thanks @ascorbic! - Exits with non-zero exit code when config has an error -
#14112
37458b3Thanks @ascorbic! - Fixes a bug that meant that SVG components could no longer be serialized withJSON.stringify -
#14061
c7a7dd5Thanks @jonasgeiler! - Add module declaration for?no-inlineasset imports -
#14109
5a08fa2Thanks @ascorbic! - Throw a more helpful error if defineLiveCollection is used outside of a live.config file -
#14110
e7dd4e1Thanks @ascorbic! - Warn if duplicate IDs are found by file loader
5.12.1
Patch Changes
-
#14094
22e9087Thanks @ascorbic! - Correct types to allowpriorityon all images -
#14091
26c6b6dThanks @ascorbic! - Fixes a bug that caused a type error when defining session options without a driver -
#14082
93322cbThanks @louisescher! - Fixes an issue where Astro's default 404 route would incorrectly match routes containing "/404" in dev -
#14089
687d253Thanks @florian-lefebvre! - Fixes a case whereastro:envwould not load the right environments variables in dev -
#14092
6692c71Thanks @ascorbic! - Improves error handling in live collections -
#14074
144a950Thanks @abcfy2! - Fixes a bug that caused some image service builds to fail -
#14092
6692c71Thanks @ascorbic! - Fixes a case where zod could not be imported fromastro:contentvirtual module in live collection config
5.12.0
Minor Changes
-
#13971
fe35ee2Thanks @adamhl8! - Adds an experimental flagrawEnvValuesto disable coercion ofimport.meta.envvalues (e.g. converting strings to other data types) that are populated fromprocess.envAstro allows you to configure a type-safe schema for your environment variables, and converts variables imported via
astro:envinto the expected type.However, Astro also converts your environment variables used through
import.meta.envin some cases, and this can prevent access to some values such as the strings"true"(which is converted to a boolean value), and"1"(which is converted to a number).The
experimental.rawEnvValuesflag disables coercion ofimport.meta.envvalues that are populated fromprocess.env, allowing you to use the raw value.To enable this feature, add the experimental flag in your Astro config:
import { defineConfig } from "astro/config" export default defineConfig({ + experimental: { + rawEnvValues: true, + } })If you were relying on this coercion, you may need to update your project code to apply it manually:
- const enabled: boolean = import.meta.env.ENABLED + const enabled: boolean = import.meta.env.ENABLED === "true"See the experimental raw environment variables reference docs for more information.
-
#13941
6bd5f75Thanks @aditsachde! - Adds support for TOML files to Astro's built-inglob()andfile()content loaders.In Astro 5.2, Astro added support for using TOML frontmatter in Markdown files instead of YAML. However, if you wanted to use TOML files as local content collection entries themselves, you needed to write your own loader.
Astro 5.12 now directly supports loading data from TOML files in content collections in both the
glob()and thefile()loaders.If you had added your own TOML content parser for the
file()loader, you can now remove it as this functionality is now included:// src/content.config.ts import { defineCollection } from "astro:content"; import { file } from "astro/loaders"; - import { parse as parseToml } from "toml"; const dogs = defineCollection({ - loader: file("src/data/dogs.toml", { parser: (text) => parseToml(text) }), + loader: file("src/data/dogs.toml") schema: /* ... */ })Note that TOML does not support top-level arrays. Instead, the
file()loader considers each top-level table to be an independent entry. The table header is populated in theidfield of the entry object.See Astro's content collections guide for more information on using the built-in content loaders.
Patch Changes
- Updated dependencies [
6bd5f75]:- @astrojs/markdown-remark@6.3.3
5.11.2
Patch Changes
-
#14064
2eb77d8Thanks @jp-knj! - Allows usingtsconfigcompilerOptions.pathswithout settingcompilerOptions.baseUrl -
#14068
10189c0Thanks @jsparkdev! - Fixes the incorrect CSS import path shown in the terminal message during Tailwind integration setup.
5.11.1
Patch Changes
-
#14045
3276b79Thanks @ghubo! - Fixes a problem where importing animated.aviffiles returns aNoImageMetadataerror. -
#14041
0c4d5f8Thanks @dixslyf! - Fixes a<ClientRouter />bug where the fallback view transition animations when exiting a page ran too early for browsers that do not support the View Transition API. This bug preventedevent.viewTransition?.skipTransition()from skipping the page exit animation when used in anastro:before-swapevent hook.
5.11.0
Minor Changes
-
#13972
db8f8beThanks @ematipico! - Updates theNodeApp.match()function in the Adapter API to accept a second, optional parameter to allow adapter authors to add headers to static, prerendered pages.NodeApp.match(request)currently checks whether there is a route that matches the givenRequest. If there is a prerendered route, the function returnsundefined, because static routes are already rendered and their headers cannot be updated.When the new, optional boolean parameter is passed (e.g.
NodeApp.match(request, true)), Astro will return the first matched route, even when it's a prerendered route. This allows your adapter to now access static routes and provides the opportunity to set headers for these pages, for example, to implement a Content Security Policy (CSP).
Patch Changes
-
#14029
42562f9Thanks @ematipico! - Fixes a bug where server islands wouldn't be correctly rendered when they are rendered inside fragments.Now the following examples work as expected:
--- import { Cart } from '../components/Cart.astro'; --- <> <Cart server:defer /> </> <Fragment slot="rest"> <Cart server:defer> <div slot="fallback">Not working</div> </Cart> </Fragment> -
#14017
8d238bcThanks @dmgawel! - Fixes a bug where i18n fallback rewrites didn't work in dynamic pages.
5.10.2
Patch Changes
-
#14000
3cbedaeThanks @feelixe! - Fix routePattern JSDoc examples to show correct return values -
#13990
de6cfd6Thanks @isVivek99! - Fixes a case whereastro:config/clientandastro:config/servervirtual modules would not contain config passed to integrationsupdateConfig()during the build -
#14019
a160d1eThanks @ascorbic! - Removes the requirement to settype: 'live'when defining experimental live content collectionsPreviously, live collections required a
typeandloaderconfigured. Now, Astro can determine that your collection is alivecollection without defining it explicitly.This means it is now safe to remove
type: 'live'from your collections defined insrc/live.config.ts:import { defineLiveCollection } from 'astro:content'; import { storeLoader } from '@mystore/astro-loader'; const products = defineLiveCollection({ - type: 'live', loader: storeLoader({ apiKey: process.env.STORE_API_KEY, endpoint: 'https://api.mystore.com/v1', }), }); export const collections = { products };This is not a breaking change: your existing live collections will continue to work even if you still include
type: 'live'. However, we suggest removing this line at your earliest convenience for future compatibility when the feature becomes stable and this config option may be removed entirely. -
#13966
598da21Thanks @msamoylov! - Fixes a broken link on the default 404 page in development
5.10.1
Patch Changes
-
#13988
609044cThanks @ascorbic! - Fixes a bug in live collections that caused it to incorrectly complain about the collection being defined in the wrong file -
#13909
b258d86Thanks @isVivek99! - Fixes rendering of special boolean attributes for custom elements -
#13983
e718375Thanks @florian-lefebvre! - Fixes a case where the toolbar audit would incorrectly flag images processed by Astro in content collections documents -
#13999
f077b68Thanks @ascorbic! - AddslastModifiedfield to experimental live collection cache hintsLive loaders can now set a
lastModifiedfield in the cache hints for entries and collections to indicate when the data was last modified. This is then available in thecacheHintfield returned bygetCollectionandgetEntry. -
#13987
08f34b1Thanks @ematipico! - Adds an informative message in dev mode when the CSP feature is enabled. -
#14005
82aad62Thanks @ematipico! - Fixes a bug where inline styles and scripts didn't work when CSP was enabled. Now when adding<styles>elements inside an Astro component, their hashes care correctly computed. -
#13985
0b4c641Thanks @jsparkdev! - Updates wrong link
5.10.0
Minor Changes
-
#13917
e615216Thanks @ascorbic! - Adds a newpriorityattribute for Astro's image components.This change introduces a new
priorityoption for the<Image />and<Picture />components, which automatically sets theloading,decoding, andfetchpriorityattributes to their optimal values for above-the-fold images which should be loaded immediately.It is a boolean prop, and you can use the shorthand syntax by simply adding
priorityas a prop to the<Image />or<Picture />component. When set, it will apply the following attributes:loading="eager"decoding="sync"fetchpriority="high"
The individual attributes can still be set manually if you need to customize your images further.
By default, the Astro
<Image />component generates<img>tags that lazy-load their content by settingloading="lazy"anddecoding="async". This improves performance by deferring the loading of images that are not immediately visible in the viewport, and gives the best scores in performance audits like Lighthouse.The new
priorityattribute will override those defaults and automatically add the best settings for your high-priority assets.This option was previously available for experimental responsive images, but now it is a standard feature for all images.
Usage
<Image src="/path/to/image.jpg" alt="An example image" priority />Note
You should only use the
priorityoption for images that are critical to the initial rendering of the page, and ideally only one image per page. This is often an image identified as the LCP element when running Lighthouse tests. Using it for too many images will lead to performance issues, as it forces the browser to load those images immediately, potentially blocking the rendering of other content. -
#13917
e615216Thanks @ascorbic! - The responsive images feature introduced behind a flag in v5.0.0 is no longer experimental and is available for general use.The new responsive images feature in Astro automatically generates optimized images for different screen sizes and resolutions, and applies the correct attributes to ensure that images are displayed correctly on all devices.
Enable the
image.responsiveStylesoption in your Astro config. Then, set alayoutattribute on any or component, or configure a defaultimage.layout, for instantly responsive images with automatically generatedsrcsetandsizesattributes based on the image's dimensions and the layout type.Displaying images correctly on the web can be challenging, and is one of the most common performance issues seen in sites. This new feature simplifies the most challenging part of the process: serving your site visitor an image optimized for their viewing experience, and for your website's performance.
For full details, see the updated Image guide.
Migration from Experimental Responsive Images
The
experimental.responsiveImagesflag has been removed, and all experimental image configuration options have been renamed to their final names.If you were using the experimental responsive images feature, you'll need to update your configuration:
Remove the experimental flag
export default defineConfig({ experimental: { - responsiveImages: true, }, });Update image configuration options
During the experimental phase, default styles were applied automatically to responsive images. Now, you need to explicitly set the
responsiveStylesoption totrueif you want these styles applied.export default defineConfig({ image: { + responsiveStyles: true, }, });The experimental image configuration options have been renamed:
Before:
export default defineConfig({ image: { experimentalLayout: 'constrained', experimentalObjectFit: 'cover', experimentalObjectPosition: 'center', experimentalBreakpoints: [640, 750, 828, 1080, 1280], experimentalDefaultStyles: true, }, experimental: { responsiveImages: true, }, });After:
export default defineConfig({ image: { layout: 'constrained', objectFit: 'cover', objectPosition: 'center', breakpoints: [640, 750, 828, 1080, 1280], responsiveStyles: true, // This is now *false* by default }, });Component usage remains the same
The
layout,fit, andpositionprops on<Image>and<Picture>components work exactly the same as before:<Image src={myImage} alt="A responsive image" layout="constrained" fit="cover" position="center" />If you weren't using the experimental responsive images feature, no changes are required.
Please see the Image guide for more information on using responsive images in Astro.
-
#13685
3c04c1fThanks @ascorbic! - Adds experimental support for live content collectionsLive content collections are a new type of content collection that fetch their data at runtime rather than build time. This allows you to access frequently-updated data from CMSs, APIs, databases, or other sources using a unified API, without needing to rebuild your site when the data changes.
Live collections vs build-time collections
In Astro 5.0, the content layer API added support for adding diverse content sources to content collections. You can create loaders that fetch data from any source at build time, and then access it inside a page via
getEntry()andgetCollection(). The data is cached between builds, giving fast access and updates.However there is no method for updating the data store between builds, meaning any updates to the data need a full site deploy, even if the pages are rendered on-demand. This means that content collections are not suitable for pages that update frequently. Instead, today these pages tend to access the APIs directly in the frontmatter. This works, but leads to a lot of boilerplate, and means users don't benefit from the simple, unified API that content loaders offer. In most cases users tend to individually create loader libraries that they share between pages.
Live content collections solve this problem by allowing you to create loaders that fetch data at runtime, rather than build time. This means that the data is always up-to-date, without needing to rebuild the site.
How to use
To enable live collections add the
experimental.liveContentCollectionsflag to yourastro.config.mjsfile:{ experimental: { liveContentCollections: true, }, }Then create a new
src/live.config.tsfile (alongside yoursrc/content.config.tsif you have one) to define your live collections with a live loader and optionally a schema using the newdefineLiveCollection()function from theastro:contentmodule.import { defineLiveCollection } from 'astro:content'; import { storeLoader } from '@mystore/astro-loader'; const products = defineLiveCollection({ type: 'live', loader: storeLoader({ apiKey: process.env.STORE_API_KEY, endpoint: 'https://api.mystore.com/v1', }), }); export const collections = { products };You can then use the dedicated
getLiveCollection()andgetLiveEntry()functions to access your live data:--- import { getLiveCollection, getLiveEntry, render } from 'astro:content'; // Get all products const { entries: allProducts, error } = await getLiveCollection('products'); if (error) { // Handle error appropriately console.error(error.message); } // Get products with a filter (if supported by your loader) const { entries: electronics } = await getLiveCollection('products', { category: 'electronics' }); // Get a single product by ID (string syntax) const { entry: product, error: productError } = await getLiveEntry('products', Astro.params.id); if (productError) { return Astro.redirect('/404'); } // Get a single product with a custom query (if supported by your loader) using a filter object const { entry: productBySlug } = await getLiveEntry('products', { slug: Astro.params.slug }); const { Content } = await render(product); --- <h1>{product.title}</h1> <Content />See the docs for the experimental live content collections feature for more details on how to use this feature, including how to create a live loader. Please give feedback on the RFC PR if you have any suggestions or issues.
Patch Changes
-
#13957
304df34Thanks @ematipico! - Fixes an issue wherereport-uriwasn't available inexperimental.csp.directives, causing a typing error and a runtime validation error. -
#13957
304df34Thanks @ematipico! - Fixes a type error for the CSP directivesupgrade-insecure-requests,sandbox, andtrusted-type. -
#13862
fe8f61aThanks @florian-lefebvre! - Fixes a case where the dev toolbar would crash if it could not retrieve some essential data -
#13976
0a31d99Thanks @florian-lefebvre! - Fixes a case where Astro Actions types would be broken when using atsconfig.jsonwith"moduleResolution": "nodenext"
5.9.4
Patch Changes
-
#13951
7eb88f1Thanks @ascorbic! - Fixes a issue that caused errors when using an adapter-provided session driver with custom options -
#13953
448bddcThanks @zaitovalisher! - Fixes a bug where quotes were not added to the 'strict-dynamic' CSP directive
5.9.3
Patch Changes
-
#13923
a9ac5edThanks @ematipico! - BREAKING CHANGE to the experimental Content Security Policy (CSP) onlyChanges the behavior of experimental Content Security Policy (CSP) to now serve hashes differently depending on whether or not a page is prerendered:
- Via the
<meta>element for static pages. - Via the
Responseheadercontent-security-policyfor on-demand rendered pages.
This new strategy allows you to add CSP content that is not supported in a
<meta>element (e.g.report-uri,frame-ancestors, and sandbox directives) to on-demand rendered pages.No change to your project code is required as this is an implementation detail. However, this will result in a different HTML output for pages that are rendered on demand. Please check your production site to verify that CSP is working as intended.
To keep up to date with this developing feature, or to leave feedback, visit the CSP Roadmap proposal.
- Via the
-
#13926
953a249Thanks @ematipico! - Adds a new Astro Adapter Feature calledexperimentalStaticHeadersto allow your adapter to receive theHeadersfor rendered static pages.Adapters that enable support for this feature can access header values directly, affecting their handling of some Astro features such as Content Security Policy (CSP). For example, Astro will no longer serve the CSP
<meta http-equiv="content-security-policy">element in static pages to adapters with this support.Astro will serve the value of the header inside a map that can be retrieved from the hook
astro:build:generated. Adapters can read this mapping and use their hosting headers capabilities to create a configuration file.A new field called
experimentalRouteToHeaderswill contain a map ofMap<IntegrationResolvedRoute, Headers>where theHeaderstype contains the headers emitted by the rendered static route.To enable support for this experimental Astro Adapter Feature, add it to your
adapterFeaturesin your adapter config:// my-adapter.mjs export default function createIntegration() { return { name: '@example/my-adapter', hooks: { 'astro:config:done': ({ setAdapter }) => { setAdapter({ name: '@example/my-adapter', serverEntrypoint: '@example/my-adapter/server.js', adapterFeatures: { experimentalStaticHeaders: true, }, }); }, }, }; }See the Adapter API docs for more information about providing adapter features.
-
#13697
af83b85Thanks @benosmac! - Fixes issues with fallback route pattern matching wheni18n.routing.fallbackTypeisrewrite.- Adds conditions for route matching in
generatePathwhen building fallback routes and checking for existing translated pages
Now for a route to be matched it needs to be inside a named
[locale]folder. This fixes an issue whereroute.pattern.test()incorrectly matched dynamic routes, causing the page to be skipped.- Adds conditions for route matching in
findRouteToRewrite
Now the requested pathname must exist in
route.distURLfor a dynamic route to match. This fixes an issue whereroute.pattern.test()incorrectly matched dynamic routes, causing the build to fail. - Adds conditions for route matching in
-
#13924
1cd8c3bThanks @qw-in! - Fixes an edge case whereisPrerenderedwas incorrectly set tofalsefor static redirects. -
#13926
953a249Thanks @ematipico! - Fixes an issue where the experimental CSPmetaelement wasn't placed in the<head>element as early as possible, causing these policies to not apply to styles and scripts that came before themetaelement.
5.9.2
Patch Changes
-
#13919
423fe60Thanks @ematipico! - Fixes a bug where Astro added quotes to the CSP resources.Only certain resources require quotes (e.g.
'self'but nothttps://cdn.example.com), so Astro no longer adds quotes to any resources. You must now provide the quotes yourself for resources such as'self'when necessary:export default defineConfig({ experimental: { csp: { styleDirective: { resources: [ - "self", + "'self'", "https://cdn.example.com" ] } } } }) -
#13914
76c5480Thanks @ematipico! - BREAKING CHANGE to the experimental Content Security Policy feature onlyRemoves support for experimental Content Security Policy (CSP) when using the
<ClientRouter />component for view transitions.It is no longer possible to enable experimental CSP while using Astro's view transitions. Support was already unstable with the
<ClientRouter />because CSP required making its underlying implementation asynchronous. This caused breaking changes for several users and therefore, this PR removes support completely.If you are currently using the component for view transitions, please remove the experimental CSP flag as they cannot be used together.
import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { - csp: true } });Alternatively, to continue using experimental CSP in your project, you can consider migrating to the browser native View Transition API and remove the
<ClientRouter />from your project. You may be able to achieve similar results if you are not using Astro's enhancements to the native View Transitions and Navigation APIs.Support might be reintroduced in future releases. You can follow this experimental feature's development in the CSP RFC.
5.9.1
Patch Changes
-
#13899
7a1303dThanks @reknih! - Fix bug where error pages would return invalid bodies if the upstream response was compressed -
#13902
051bc30Thanks @arHSM! - Fixes a bug where vite virtual module ids were incorrectly added in the dev server -
#13905
81f71caThanks @jsparkdev! - Fixes wrong contents in CSP meta tag. -
#13907
8246bccThanks @martrapp! - Fixes a bug that caused view transition names to be lost. -
#13901
37fa0a2Thanks @ansg191! - fix fallback not being removed when server island is rendered
5.9.0
Minor Changes
-
#13802
0eafe14Thanks @ematipico! - Adds experimental Content Security Policy (CSP) supportCSP is an important feature to provide fine-grained control over resources that can or cannot be downloaded and executed by a document. In particular, it can help protect against cross-site scripting (XSS) attacks.
Enabling this feature adds additional security to Astro's handling of processed and bundled scripts and styles by default, and allows you to further configure these, and additional, content types. This new experimental feature has been designed to work in every Astro rendering environment (static pages, dynamic pages and single page applications), while giving you maximum flexibility and with type-safety in mind.
It is compatible with most of Astro's features such as client islands, and server islands, although Astro's view transitions using the
<ClientRouter />are not yet fully supported. Inline scripts are not supported out of the box, but you can provide your own hashes for external and inline scripts.To enable this feature, add the experimental flag in your Astro config:
// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { csp: true, }, });For more information on enabling and using this feature in your project, see the Experimental CSP docs.
For a complete overview, and to give feedback on this experimental API, see the Content Security Policy RFC.
-
#13850
1766d22Thanks @ascorbic! - Provides a Markdown renderer to content loadersWhen creating a content loader, you will now have access to a
renderMarkdownfunction that allows you to render Markdown content directly within your loaders. It uses the same settings and plugins as the renderer used for Markdown files in Astro, and follows any Markdown settings you have configured in your Astro project.This allows you to render Markdown content from various sources, such as a CMS or other data sources, directly in your loaders without needing to preprocess the Markdown content separately.
import type { Loader } from 'astro/loaders'; import { loadFromCMS } from './cms'; export function myLoader(settings): Loader { return { name: 'my-loader', async load({ renderMarkdown, store }) { const entries = await loadFromCMS(); store.clear(); for (const entry of entries) { // Assume each entry has a 'content' field with markdown content store.set({ id: entry.id, data: entry, rendered: await renderMarkdown(entry.content), }); } }, }; }The return value of
renderMarkdownis an object with two properties:htmlandmetadata. These match therenderedproperty of content entries in content collections, so you can use them to render the content in your components or pages.--- import { getEntry, render } from 'astro:content'; const entry = await getEntry('my-collection', Astro.params.id); const { Content } = await render(entry); --- <Content />For more information, see the Content Loader API docs.
-
#13887
62f0668Thanks @yanthomasdev! - Adds an option for integration authors to suppress adapter warning/errors insupportedAstroFeatures. This is useful when either an warning/error isn't applicable in a specific context or the default one might conflict and confuse users.To do so, you can add
suppress: "all"(to suppress both the default and custom message) orsuppress: "default"(to only suppress the default one):setAdapter({ name: 'my-astro-integration', supportedAstroFeatures: { staticOutput: 'stable', hybridOutput: 'stable', sharpImageService: { support: 'limited', message: "The sharp image service isn't available in the deploy environment, but will be used by prerendered pages on build.", suppress: 'default', }, }, });For more information, see the Adapter API reference docs.
5.8.2
Patch Changes
-
#13877
5a7797fThanks @yuhang-dong! - Fixes a bug that causedAstro.rewriteto fail when used insequenced middleware -
#13872
442b841Thanks @isVivek99! - Fixes rendering of thedownloadattribute when it has a boolean value
5.8.1
Patch Changes
-
#13037
de2fc9bThanks @nanarino! - Fixes rendering of thepopoverattribute when it has a boolean value -
#13851
45ae95aThanks @ascorbic! - Allows disabling default styles for responsive imagesThis change adds a new
image.experimentalDefaultStylesoption that allows you to disable the default styles applied to responsive images.When using experimental responsive images, Astro applies default styles to ensure the images resize correctly. In most cases this is what you want – and they are applied with low specificity so your own styles override them. However in some cases you may want to disable these default styles entirely. This is particularly useful when using Tailwind 4, because it uses CSS cascade layers to apply styles, making it difficult to override the default styles.
image.experimentalDefaultStylesis a boolean option that defaults totrue, so you can change it in your Astro config file like this:export default { image: { experimentalDefaultStyles: false, }, experimental: { responsiveImages: true, }, }; -
#13858
cb1a168Thanks @florian-lefebvre! - Fixes the warning shown when client directives are used on Astro components -
#12574
da266d0Thanks @apatel369! - Allows using server islands in mdx files -
#13843
fbcfa68Thanks @z1haze! - Export typeAstroSessionto allow use in explicitly typed safe code.
5.8.0
Minor Changes
-
#13809
3c3b492Thanks @ascorbic! - Increases minimum Node.js version to 18.20.8Node.js 18 has now reached end-of-life and should not be used. For now, Astro will continue to support Node.js 18.20.8, which is the final LTS release of Node.js 18, as well as Node.js 20 and Node.js 22 or later. We will drop support for Node.js 18 in a future release, so we recommend upgrading to Node.js 22 as soon as possible. See Astro's Node.js support policy for more details.
⚠️ Important note for users of Cloudflare Pages: The current build image for Cloudflare Pages uses Node.js 18.17.1 by default, which is no longer supported by Astro. If you are using Cloudflare Pages you should override the default Node.js version to Node.js 22. This does not affect users of Cloudflare Workers, which uses Node.js 22 by default.
Patch Changes
- Updated dependencies [
3c3b492]:- @astrojs/telemetry@3.3.0
- @astrojs/markdown-remark@6.3.2
5.7.14
Patch Changes
-
#13773
3aa5337Thanks @sijad! - Ignores lightningcss unsupported pseudo-class warning. -
#13833
5a6d2aeThanks @ascorbic! - Fixes an issue where session modules would fail to resolve in Node.js < 20.6 -
#13383
f7f712cThanks @Haberkamp! - Stop toolbar settings from overflowing -
#13794
85b19d8Thanks @alexcarpenter! - Exclude pre tags froma11y-no-noninteractive-tabindexaudit check. -
#13373
50ef568Thanks @jpwienekus! - Fixes a bug where highlights and tooltips render over the audit list window. -
#13769
e9fc456Thanks @romanstetsyk! - Expand ActionError codes to include all IANA-registered HTTP error codes. -
#13668
866285aThanks @sapphi-red! - Replaces internal CSS chunking behavior for Astro components' scoped styles to use Vite'scssScopeTofeature. The feature is a port of Astro's implementation so this should not change the behavior.
5.7.13
Patch Changes
-
#13761
a2e8463Thanks @jp-knj! - Adds new content collections errors -
#13788
7d0b7acThanks @florian-lefebvre! - Fixes a case where an error would not be thrown when using the<Font />component from the experimental fonts API without adding fonts in the Astro config -
#13784
d7a1889Thanks @florian-lefebvre! - Fixes the experimental fonts API to correctly takeconfig.base,config.build.assetsandconfig.build.assetsPrefixinto account -
#13777
a56b8eaThanks @L4Ph! - Fixed an issue where looping GIF animation would stop when converted to WebP -
#13566
0489d8fThanks @TheOtterlord! - Fix build errors being ignored when build.concurrency > 1
5.7.12
Patch Changes
-
#13752
a079c21Thanks @florian-lefebvre! - Improves handling of font URLs not ending with a file extension when using the experimental fonts API -
#13750
7d3127dThanks @martrapp! - Allows the ClientRouter to open new tabs or windows when submitting forms by clicking while holding the Cmd, Ctrl, or Shift key. -
#13765
d874fe0Thanks @florian-lefebvre! - Fixes a case where font sources with relative protocol URLs would fail when using the experimental fonts API -
#13640
5e582e7Thanks @florian-lefebvre! - Allows inferringweightandstylewhen using the local provider of the experimental fonts APIIf you want Astro to infer those properties directly from your local font files, leave them undefined:
{ // No weight specified: infer style: 'normal'; // Do not infer }
5.7.11
Patch Changes
-
#13734
30aec73Thanks @ascorbic! - Loosen content layer schema types -
#13751
5816b8aThanks @florian-lefebvre! - Updatesunifontto support subsets when using thegoogleprovider with the experimental fonts API -
#13756
d4547baThanks @florian-lefebvre! - Adds a terminal warning when a remote provider returns no data for a family when using the experimental fonts API -
#13742
f599463Thanks @florian-lefebvre! - Fixes optimized fallback css generation to properly add asrcwhen using the experimental fonts API -
#13740
6935540Thanks @vixalien! - Fix cookies set after middleware did a rewrite withnext(url)not being applied -
#13759
4a56d0aThanks @jp-knj! - Improved the error handling of certain error cases.
5.7.10
Patch Changes
- #13731
c3e80c2Thanks @jsparkdev! - update vite to latest version for fixing CVE
5.7.9
Patch Changes
5.7.8
Patch Changes
- #13715
b32dffaThanks @florian-lefebvre! - Updatesunifontto fix a case where aunicodeRangerelated error would be thrown when using the experimental fonts API
5.7.7
Patch Changes
-
#13705
28f8716Thanks @florian-lefebvre! - Updates unifont to latest and adds support forfetchoptions from remote providers when using the experimental fonts API -
#13692
60d5be4Thanks @Le0Developer! - Fixes a bug where Astro couldn't probably useinferSizefor images that contain apostrophe'in their name. -
#13698
ab98f88Thanks @sarah11918! - Improves the configuration reference docs for theadapterentry with more relevant text and links. -
#13706
b4929aeThanks @ascorbic! - Fixes typechecking for content config schema -
#13653
a7b2dc6Thanks @florian-lefebvre! - Reduces the amount of preloaded files for the local provider when using the experimental fonts API -
#13653
a7b2dc6Thanks @florian-lefebvre! - Fixes a case where invalid CSS was emitted when using an experimental fonts API family name containing a space
5.7.6
Patch Changes
-
#13703
659904bThanks @ascorbic! - Fixes a bug where empty fallbacks could not be provided when using the experimental fonts API -
#13680
18e1b97Thanks @florian-lefebvre! - Improves theUnsupportedExternalRedirecterror message to include more details such as the concerned destination -
#13703
659904bThanks @ascorbic! - Simplifies styles for experimental responsive images⚠️ BREAKING CHANGE FOR EXPERIMENTAL RESPONSIVE IMAGES ONLY ⚠️
The generated styles for image layouts are now simpler and easier to override. Previously the responsive image component used CSS to set the size and aspect ratio of the images, but this is no longer needed. Now the styles just include
object-fitandobject-positionfor all images, and setsmax-width: 100%for constrained images andwidth: 100%for full-width images.This is an implementation change only, and most users will see no change. However, it may affect any custom styles you have added to your responsive images. Please check your rendered images to determine whether any change to your CSS is needed.
The styles now use the
:where()pseudo-class, which has a specificity of 0, meaning that it is easy to override with your own styles. You can now be sure that your own classes will always override the applied styles, as will global styles onimg.An exception is Tailwind 4, which uses cascade layers, meaning the rules are always lower specificity. Astro supports browsers that do not support cascade layers, so we cannot use this. If you need to override the styles using Tailwind 4, you must use
!importantclasses. Do check if this is needed though: there may be a layout that is more appropriate for your use case. -
#13703
659904bThanks @ascorbic! - Adds warnings about using local font files in thepublicDirwhen the experimental fonts API is enabled. -
#13703
659904bThanks @ascorbic! - Renames experimental responsive image layout option from "responsive" to "constrained"⚠️ BREAKING CHANGE FOR EXPERIMENTAL RESPONSIVE IMAGES ONLY ⚠️
The layout option called
"responsive"is renamed to"constrained"to better reflect its behavior.The previous name was causing confusion, because it is also the name of the feature. The
responsivelayout option is specifically for images that are displayed at the requested size, unless they do not fit the width of their container, at which point they would be scaled down to fit. They do not get scaled beyond the intrinsic size of the source image, or thewidthprop if provided.It became clear from user feedback that many people (understandably) thought that they needed to set
layouttoresponsiveif they wanted to use responsive images. They then struggled with overriding styles to make the image scale up for full-width hero images, for example, when they should have been usingfull-widthlayout. Renaming the layout toconstrainedshould make it clearer that this layout is for when you want to constrain the maximum size of the image, but allow it to scale-down.Upgrading
If you set a default
image.experimentalLayoutin yourastro.config.mjs, or set it on a per-image basis using thelayoutprop, you will need to change all occurences toconstrained:// astro.config.mjs export default { image: { - experimentalLayout: 'responsive', + experimentalLayout: 'constrained', }, }// src/pages/index.astro --- import { Image } from 'astro:assets'; --- - <Image src="/image.jpg" layout="responsive" /> + <Image src="/image.jpg" layout="constrained" />Please give feedback on the RFC if you have any questions or comments about the responsive images API.
5.7.5
Patch Changes
-
#13660
620d15dThanks @mingjunlu! - Addsserver.allowedHostsdocs comment toAstroUserConfig -
#13591
5dd2d3fThanks @florian-lefebvre! - Removes unused code -
#13669
73f24d4Thanks @ematipico! - Fixes an issue whereAstro.originPathnamewasn't returning the correct value when using rewrites. -
#13674
42388b2Thanks @florian-lefebvre! - Fixes a case where an experimental fonts API error would be thrown when using anotherastro:assetsAPI -
#13654
4931457Thanks @florian-lefebvre! - FixesfontProviders.google()so it can forward options to the unifont provider, when using the experimental fonts API -
Updated dependencies [
5dd2d3f]:- @astrojs/telemetry@3.2.1
5.7.4
Patch Changes
-
#13647
ffbe8f2Thanks @ascorbic! - Fixes a bug that caused a session error to be logged when using actions without sessions -
#13646
6744842Thanks @florian-lefebvre! - Fixes a case where extra font sources were removed when using the experimental fonts API -
#13635
d75cac4Thanks @florian-lefebvre! - The experimental fonts API now generates optimized fallbacks for every weight and style
5.7.3
Patch Changes
-
#13643
67b7493Thanks @tanishqmanuja! - Fixes a case where the font facesrcformat would be invalid when using the experimental fonts API -
#13639
23410c6Thanks @florian-lefebvre! - Fixes a case where some font families would not be downloaded when using the same font provider several times, using the experimental fonts API
5.7.2
Patch Changes
-
#13632
cb05cfbThanks @florian-lefebvre! - Improves the optimized fallback name generated by the experimental Fonts API -
#13630
3e7db4fThanks @florian-lefebvre! - Fixes a case where fonts using a local provider would not work because of an invalid generatedsrc -
#13634
516de7dThanks @ematipico! - Fixes a regression where usingnext('/')didn't correctly return the requested route. -
#13632
cb05cfbThanks @florian-lefebvre! - Improves the quality of optimized fallbacks generated by the experimental Fonts API -
#13616
d475afcThanks @lfilho! - Fixes a regression where relative static redirects didn't work as expected.
5.7.1
Patch Changes
-
#13594
dc4a015Thanks @florian-lefebvre! - Reduces the number of font files downloaded -
#13627
7f1a624Thanks @florian-lefebvre! - Fixes a case where using the<Font />component would throw a Rollup error during the build -
#13626
3838efeThanks @florian-lefebvre! - Updates fallback font generation to always read font files returned by font providers -
#13625
f1311d2Thanks @florian-lefebvre! - Updates the<Font />component so that preload links are generated before the style tag ifpreloadis passed -
#13622
a70d32aThanks @ascorbic! - Improve autocomplete for session keys
5.7.0
Minor Changes
-
#13527
2fd6a6bThanks @ascorbic! - The experimental session API introduced in Astro 5.1 is now stable and ready for production use.Sessions are used to store user state between requests for on-demand rendered pages. You can use them to store user data, such as authentication tokens, shopping cart contents, or any other data that needs to persist across requests:
--- export const prerender = false; // Not needed with 'server' output const cart = await Astro.session.get('cart'); --- <a href="/checkout">🛒 {cart?.length ?? 0} items</a>Configuring session storage
Sessions require a storage driver to store the data. The Node, Cloudflare and Netlify adapters automatically configure a default driver for you, but other adapters currently require you to specify a custom storage driver in your configuration.
If you are using an adapter that doesn't have a default driver, or if you want to choose a different driver, you can configure it using the
sessionconfiguration option:import { defineConfig } from 'astro/config'; import vercel from '@astrojs/vercel'; export default defineConfig({ adapter: vercel(), session: { driver: 'upstash', }, });Using sessions
Sessions are available in on-demand rendered pages, API endpoints, actions and middleware.
In pages and components, you can access the session using
Astro.session:--- const cart = await Astro.session.get('cart'); --- <a href="/checkout">🛒 {cart?.length ?? 0} items</a>In endpoints, actions, and middleware, you can access the session using
context.session:export async function GET(context) { const cart = await context.session.get('cart'); return Response.json({ cart }); }If you attempt to access the session when there is no storage driver configured, or in a prerendered page, the session object will be
undefinedand an error will be logged in the console:--- export const prerender = true; const cart = await Astro.session?.get('cart'); // Logs an error. Astro.session is undefined ---Upgrading from Experimental to Stable
If you were previously using the experimental API, please remove the
experimental.sessionflag from your configuration:import { defineConfig } from 'astro/config'; import node from '@astrojs/node'; export default defineConfig({ adapter: node({ mode: "standalone", }), - experimental: { - session: true, - }, });See the sessions guide for more information.
-
#12775
b1fe521Thanks @florian-lefebvre! - Adds a new, experimental Fonts API to provide first-party support for fonts in Astro.This experimental feature allows you to use fonts from both your file system and several built-in supported providers (e.g. Google, Fontsource, Bunny) through a unified API. Keep your site performant thanks to sensible defaults and automatic optimizations including fallback font generation.
To enable this feature, configure an
experimental.fontsobject with one or more fonts:import { defineConfig, fontProviders } from "astro/config" export default defineConfig({ experimental: { fonts: [{ provider: fontProviders.google(), ` name: "Roboto", cssVariable: "--font-roboto", }] } })Then, add a
<Font />component and site-wide styling in your<head>:--- import { Font } from 'astro:assets'; --- <Font cssVariable="--font-roboto" preload /> <style> body { font-family: var(--font-roboto); } </style>Visit the experimental Fonts documentation for the full API, how to get started, and even how to build your own custom
AstroFontProviderif we don't yet support your preferred font service.For a complete overview, and to give feedback on this experimental API, see the Fonts RFC and help shape its future.
-
#13560
df3fd54Thanks @ematipico! - The virtual moduleastro:configintroduced behind a flag in v5.2.0 is no longer experimental and is available for general use.This virtual module exposes two sub-paths for type-safe, controlled access to your configuration:
astro:config/client: exposes config information that is safe to expose to the client.astro:config/server: exposes additional information that is safe to expose to the server, such as file and directory paths.
Access these in any file inside your project to import and use select values from your Astro config:
// src/utils.js import { trailingSlash } from 'astro:config/client'; function addForwardSlash(path) { if (trailingSlash === 'always') { return path.endsWith('/') ? path : path + '/'; } else { return path; } }If you were previously using this feature, please remove the experimental flag from your Astro config:
// astro.config.mjs export default defineConfig({ - experimental: { - serializeConfig: true - } })If you have been waiting for feature stabilization before using configuration imports, you can now do so.
Please see the
astro:configreference for more about this feature. -
#13578
406501aThanks @stramel! - The SVG import feature introduced behind a flag in v5.0.0 is no longer experimental and is available for general use.This feature allows you to import SVG files directly into your Astro project as components and inline them into your HTML.
To use this feature, import an SVG file in your Astro project, passing any common SVG attributes to the imported component.
--- import Logo from './path/to/svg/file.svg'; --- <Logo width={64} height={64} fill="currentColor" />If you have been waiting for stabilization before using the SVG Components feature, you can now do so.
If you were previously using this feature, please remove the experimental flag from your Astro config:
import { defineConfig } from 'astro' export default defineConfig({ - experimental: { - svg: true, - } })Additionally, a few features that were available during the experimental stage were removed in a previous release. Please see the v5.6.0 changelog for details if you have not yet already updated your project code for the experimental feature accordingly.
Please see the SVG Components guide in docs for more about this feature.
Patch Changes
-
#13602
3213450Thanks @natemoo-re! - Updates the Audit dev toolbar app to automatically stripdata-astro-source-fileanddata-astro-source-locattributes in dev mode. -
#13598
f5de51eThanks @dreyfus92! - Fix routing with base paths when trailingSlash is set to 'never'. This ensures requests to '/base' are correctly matched when the base path is set to '/base', without requiring a trailing slash. -
#13603
d038030Thanks @sarah11918! - Adds the minimal starter template to the list ofcreate astrooptionsGood news if you're taking the introductory tutorial in docs, making a minimal reproduction, or just want to start a project with as little to rip out as possible. Astro's
minimal(empty) template is now back as one of the options when runningcreate astro@latestand starting a new project!
5.6.2
Patch Changes
-
#13606
793ecd9Thanks @natemoo-re! - Fixes a regression that allowed prerendered code to leak into the server bundle. -
#13576
1c60ec3Thanks @ascorbic! - Reduces duplicate code in server islands scripts by extracting shared logic into a helper function. -
#13588
57e59beThanks @natemoo-re! - Fixes a memory leak when using SVG assets. -
#13589
5a0563dThanks @ematipico! - Deprecates the asset utility functionemitESMImage()and adds a newemitImageMetadata()to be used insteadThe function
emitESMImage()is now deprecated. It will continue to function, but it is no longer recommended nor supported. This function will be completely removed in a next major release of Astro.Please replace it with the new function
emitImageMetadata()as soon as you are able to do so:- import { emitESMImage } from "astro/assets/utils"; + import { emitImageMetadata } from "astro/assets/utils";The new function returns the same signature as the previous one. However, the new function removes two deprecated arguments that were not meant to be exposed for public use:
_watchModeandexperimentalSvgEnabled. Since it was possible to access these with the old function, you may need to verify that your code still works as intended withemitImageMetadata(). -
#13596
3752519Thanks @jsparkdev! - update vite to latest version to fix CVE -
#13547
360cb91Thanks @jsparkdev! - Updates vite to the latest version -
#13548
e588527Thanks @ryuapp! - Support for Deno to install npm pacakges.Deno requires npm prefix to install packages on npm. For example, to install react, we need to run
deno add npm:react. But currently the command executed isdeno add react, which doesn't work. So, we change the package names to have an npm prefix if you are using Deno. -
#13587
a0774b3Thanks @robertoms99! - Fixes an issue with the client router where some attributes of the root element were not updated during swap, including the transition scope.
5.6.1
Patch Changes
-
#13519
3323f5cThanks @florian-lefebvre! - Refactors some internals to improve Rolldown compatibility -
#13545
a7aff41Thanks @stramel! - Prevent empty attributes from appearing in the SVG output -
#13552
9cd0fd4Thanks @ematipico! - Fixes an issue where Astro validated the i18n configuration incorrectly, causing false positives in downstream libraries.
5.6.0
Minor Changes
-
#13403
dcb9526Thanks @yurynix! - Adds a new optionalprerenderedErrorPageFetchoption in the Adapter API to allow adapters to provide custom implementations for fetching prerendered error pages.Now, adapters can override the default
fetch()behavior, for example whenfetch()is unavailable or when you cannot call the server from itself.The following example provides a custom fetch for
500.htmland404.html, reading them from disk instead of performing an HTTP call:return app.render(request, { prerenderedErrorPageFetch: async (url: string): Promise<Response> => { if (url.includes("/500")) { const content = await fs.promises.readFile("500.html", "utf-8"); return new Response(content, { status: 500, headers: { "Content-Type": "text/html" }, }); } const content = await fs.promises.readFile("404.html", "utf-8"); return new Response(content, { status: 404, headers: { "Content-Type": "text/html" }, }); });If no value is provided, Astro will fallback to its default behavior for fetching error pages.
Read more about this feature in the Adapter API reference.
-
#13482
ff257dfThanks @florian-lefebvre! - Updates Astro config validation to also run for the Integration API. An error log will specify which integration is failing the validation.Now, Astro will first validate the user configuration, then validate the updated configuration after each integration
astro:config:setuphook has run. This meansupdateConfig()calls will no longer accept invalid configuration.This fixes a situation where integrations could potentially update a project with a malformed configuration. These issues should now be caught and logged so that you can update your integration to only set valid configurations.
-
#13405
21e7e80Thanks @Marocco2! - Adds a neweagernessoption forprefetch()when usingexperimental.clientPrerenderWith the experimental
clientPrerenderflag enabled, you can use theeagernessoption onprefetch()to suggest to the browser how eagerly it should prefetch/prerender link targets.This follows the same API described in the Speculation Rules API and allows you to balance the benefit of reduced wait times against bandwidth, memory, and CPU costs for your site visitors.
For example, you can now use
prefetch()programmatically with large sets of links and avoid browser limits in place to guard against over-speculating (prerendering/prefetching too many links). Seteagerness: 'moderate'to take advantage of First In, First Out (FIFO) strategies and browser heuristics to let the browser decide when to prerender/prefetch them and in what order:<a class="link-moderate" href="/nice-link-1">A Nice Link 1</a> <a class="link-moderate" href="/nice-link-2">A Nice Link 2</a> <a class="link-moderate" href="/nice-link-3">A Nice Link 3</a> <a class="link-moderate" href="/nice-link-4">A Nice Link 4</a> ... <a class="link-moderate" href="/nice-link-20">A Nice Link 20</a> <script> import { prefetch } from 'astro:prefetch'; const linkModerate = document.getElementsByClassName('link-moderate'); linkModerate.forEach((link) => prefetch(link.getAttribute('href'), { eagerness: 'moderate' })); </script> -
#13482
ff257dfThanks @florian-lefebvre! - Improves integrations error handlingIf an error is thrown from an integration hook, an error log will now provide information about the concerned integration and hook
Patch Changes
-
#13539
c43bf8cThanks @ascorbic! - Adds a newsession.load()method to the experimental session API that allows you to load a session by ID.When using the experimental sessions API, you don't normally need to worry about managing the session ID and cookies: Astro automatically reads the user's cookies and loads the correct session when needed. However, sometimes you need more control over which session to load.
The new
load()method allows you to manually load a session by ID. This is useful if you are handling the session ID yourself, or if you want to keep track of a session without using cookies. For example, you might want to restore a session from a logged-in user on another device, or work with an API endpoint that doesn't use cookies.// src/pages/api/cart.ts import type { APIRoute } from 'astro'; export const GET: APIRoute = async ({ session, request }) => { // Load the session from a header instead of cookies const sessionId = request.headers.get('x-session-id'); await session.load(sessionId); const cart = await session.get('cart'); return Response.json({ cart }); };If a session with that ID doesn't exist, a new one will be created. This allows you to generate a session ID in the client if needed.
For more information, see the experimental sessions docs.
-
#13488
d777420Thanks @stramel! - BREAKING CHANGE to the experimental SVG Component API onlyRemoves some previously available prop, attribute, and configuration options from the experimental SVG API. These items are no longer available and must be removed from your code:
-
The
titleprop has been removed until we can settle on the correct balance between developer experience and accessibility. Please replace anytitleprops on your components witharia-label:- <Logo title="My Company Logo" /> + <Logo aria-label="My Company Logo" /> -
Sprite mode has been temporarily removed while we consider a new implementation that addresses how this feature was being used in practice. This means that there are no longer multiple
modeoptions, and all SVGs will be inline. All instances ofmodemust be removed from your project as you can no longer control a mode:- <Logo mode="inline" /> + <Logo />import { defineConfig } from 'astro' export default defineConfig({ experimental: { - svg: { - mode: 'sprite' - }, + svg: true } }); -
The default
roleis no longer applied due to developer feedback. Please add the appropriateroleon each component individually as needed:- <Logo /> + <Logo role="img" /> // To keep the role that was previously applied by default -
The
sizeprop has been removed to better work in combination withviewBoxand additional styles/attributes. Please replacesizewith explicitwidthandheightattributes:- <Logo size={64} /> + <Logo width={64} height={64} />
-
5.5.6
Patch Changes
-
#13429
06de673Thanks @ematipico! - TheActionAPIContext.rewritemethod is deprecated and will be removed in a future major version of Astro -
#13524
82cd583Thanks @ematipico! - Fixes a bug where the functionsAstro.preferredLocaleandAstro.preferredLocaleListwould return the incorrect locales when the Astro configuration specifies a list ofcodes. Before, the functions would return thepath, instead now the functions return a list built fromcodes. -
#13526
ff9d69eThanks @jsparkdev! - updateviteto the latest version
5.5.5
Patch Changes
-
#13510
5b14d33Thanks @florian-lefebvre! - Fixes a case whereastro:envsecrets used in actions would not be available -
#13485
018fbe9Thanks @ascorbic! - Fixes a bug that caused cookies to ignore custom decode function if has() had been called before -
#13505
a98ae5bThanks @ematipico! - Updates the dependencyviteto the latest. -
#13483
fc2dcb8Thanks @ematipico! - Fixes a bug where an Astro adapter couldn't call the middleware when there isn't a route that matches the incoming request.
5.5.4
Patch Changes
-
#13457
968e713Thanks @ascorbic! - Sets correct response status text for custom error pages -
#13447
d80ba2bThanks @ematipico! - Fixes an issue wheresitewas added to the generated redirects. -
#13481
e9e9245Thanks @martrapp! - Makes server island work with the client router again. -
#13484
8b5e4dcThanks @ascorbic! - Display useful errors when config loading fails because of Node addons being disabled on Stackblitz
5.5.3
Patch Changes
-
#13437
013fa87Thanks @Vardhaman619! - Handle server.allowedHosts when the value is true without attempting to push it into an array. -
#13324
ea74336Thanks @ematipico! - Upgrade to shiki v3 -
#13372
7783dbfThanks @ascorbic! - Fixes a bug that caused some very large data stores to save incomplete data. -
#13358
8c21663Thanks @ematipico! - Adds a new function calledinsertPageRouteto the Astro Container API.The new function is useful when testing routes that, for some business logic, use
Astro.rewrite.For example, if you have a route
/blog/postand for some business decision there's a rewrite to/generic-error, the container API implementation will look like this:import Post from '../src/pages/Post.astro'; import GenericError from '../src/pages/GenericError.astro'; import { experimental_AstroContainer as AstroContainer } from 'astro/container'; const container = await AstroContainer.create(); container.insertPageRoute('/generic-error', GenericError); const result = await container.renderToString(Post); console.log(result); // this should print the response from GenericError.astroThis new method only works for page routes, which means that endpoints aren't supported.
-
#13426
565583bThanks @ascorbic! - Fixes a bug that caused theastro addcommand to ignore the--yesflag for third-party integrations -
#13428
9cac9f3Thanks @matthewp! - Prevent bad value in x-forwarded-host from crashing request -
#13432
defad33Thanks @P4tt4te! - Fix an issue in the Container API, where therenderToStringfunction doesn't render adequately nested slots when they are components. -
Updated dependencies [
ea74336]:- @astrojs/markdown-remark@6.3.1
5.5.2
Patch Changes
-
#13415
be866a1Thanks @ascorbic! - Reuses experimental session storage object between requests. This prevents memory leaks and improves performance for drivers that open persistent connections to a database. -
#13420
2f039b9Thanks @ematipico! - It fixes an issue that caused some regressions in how styles are bundled.
5.5.1
Patch Changes
5.5.0
Minor Changes
-
#13402
3e7b498Thanks @ematipico! - Adds a new experimental flag calledexperimental.preserveScriptOrderthat renders<script>and<style>tags in the same order as they are defined.When rendering multiple
<style>and<script>tags on the same page, Astro currently reverses their order in your generated HTML output. This can give unexpected results, for example CSS styles being overridden by earlier defined style tags when your site is built.With the new
preserveScriptOrderflag enabled, Astro will generate the styles in the order they are defined:import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { preserveScriptOrder: true, }, });For example, the following component has two
<style>tags, and both define the same style for thebodytag:<p>I am a component</p> <style> body { background: red; } </style> <style> body { background: yellow; } </style>Once the project is compiled, Astro will create an inline style where
yellowappears first, and thenred. Ultimately, theredbackground is applied:body { background: #ff0; } body { background: red; }When
experimental.preserveScriptOrderis set totrue, the order of the two styles is kept as it is, and in the style generatedredappears first, and thenyellow:body { background: red; } body { background: #ff0; }This is a breaking change to how Astro renders project code that contains multiple
<style>and<script>tags in the same component. If you were previously compensating for Astro's behavior by writing these out of order, you will need to update your code.This will eventually become the new default Astro behavior, so we encourage you to add this experimental style and script ordering as soon as you are able! This will help us test the new behavior and ensure your code is ready when this becomes the new normal.
For more information as this feature develops, please see the experimental script order docs.
-
#13352
cb886dcThanks @delucis! - Adds support for a newexperimental.headingIdCompatflagBy default, Astro removes a trailing
-from the end of IDs it generates for headings ending with special characters. This differs from the behavior of common Markdown processors.You can now disable this behavior with a new configuration flag:
// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { headingIdCompat: true, }, });This can be useful when heading IDs and anchor links need to behave consistently across your site and other platforms such as GitHub and npm.
If you are using the
rehypeHeadingIdsplugin directly, you can also pass this new option:// astro.config.mjs import { defineConfig } from 'astro/config'; import { rehypeHeadingIds } from '@astrojs/markdown-remark'; import { otherPluginThatReliesOnHeadingIDs } from 'some/plugin/source'; export default defineConfig({ markdown: { rehypePlugins: [ [rehypeHeadingIds, { experimentalHeadingIdCompat: true }], otherPluginThatReliesOnHeadingIDs, ], }, }); -
#13311
a3327ffThanks @chrisirhc! - Adds a new configuration option for Markdown syntax highlightingexcludeLangsThis option provides better support for diagramming tools that rely on Markdown code blocks, such as Mermaid.js and D2 by allowing you to exclude specific languages from Astro's default syntax highlighting.
This option allows you to avoid rendering conflicts with tools that depend on the code not being highlighted without forcing you to disable syntax highlighting for other code blocks.
The following example configuration will exclude highlighting for
mermaidandmathcode blocks:import { defineConfig } from 'astro/config'; export default defineConfig({ markdown: { syntaxHighlight: { type: 'shiki', excludeLangs: ['mermaid', 'math'], }, }, });Read more about this new option in the Markdown syntax highlighting configuration docs.
Patch Changes
-
#13404
4e78b4dThanks @ascorbic! - Fixes a bug in error handling that saving a content file with a schema error would display an "unhandled rejection" error instead of the correct schema error -
#13379
d59eb22Thanks @martrapp! - Fixes an edge case where the client router executed scripts twice when used with a custom swap function that only swaps parts of the DOM. -
#13393
6b8fdb8Thanks @renovate! - Updatesprimsjsto version 1.30.0, which adds support for more languages and fixes a security advisory which does not affect Astro. -
#13374
7b75bc5Thanks @ArmandPhilippot! - Fixes the documentation of the i18n configuration wheremanualwas presented as a key ofroutinginstead of an available value. -
#13380
9bfa6e6Thanks @martrapp! - Fixes an issue where astro:page-load fires before all scripts are executed -
#13407
0efdc22Thanks @ascorbic! - Displays correct error message when sharp isn't installed -
Updated dependencies [
cb886dc,a3327ff]:- @astrojs/markdown-remark@6.3.0
5.4.3
Patch Changes
-
#13381
249d52aThanks @martrapp! - Adds thetypesproperty to the viewTransition object when the ClientRouter simulates parts of the View Transition API on browsers w/o native support. -
#13367
3ce4ad9Thanks @ematipico! - Adds documentation to various utility functions used for remote image services -
#13347
d83f92aThanks @bluwy! - Updates internal CSS chunking behavior for Astro components' scoped styles. This may result in slightly more CSS chunks created, but should allow the scoped styles to only be included on pages that use them. -
#13388
afadc70Thanks @ematipico! - Fixes a bug whereastro:config/serverandastro:config/clienthad incorrect types. -
#13355
042d1deThanks @ematipico! - Adds documentation to the assets utilities for remote service images. -
#13395
6d1c63fThanks @bluwy! - Usespackage-manager-detectorto detect the package manager used in the project -
#13363
a793636Thanks @ematipico! - Fixes an issue where the internal functionmakeSvgComponentwas incorrectly exposed as a public API. -
Updated dependencies [
042d1de]:- @astrojs/internal-helpers@0.6.1
- @astrojs/markdown-remark@6.2.1
5.4.2
Patch Changes
-
#12985
84e94ccThanks @matthewp! - Prevent re-executing scripts in client router -
#13349
50e2e0bThanks @ascorbic! - Correctly escapes attributes in Markdown images -
#13262
0025df3Thanks @ematipico! - Refactor Astro Actions to not use a middleware. Doing so should avoid unexpected issues when using the Astro middleware at the edge.
5.4.1
Patch Changes
-
#13336
8f632efThanks @ematipico! - Fixes a regression where some asset utilities were move across monorepo, and not re-exported anymore. -
#13320
b5dabe9Thanks @{! - Adds support for typing experimental session dataYou can add optional types to your session data by creating a
src/env.d.tsfile in your project that extends the globalApp.SessionDatainterface. For example:declare namespace App { interface SessionData { id: string; email: string; }; lastLogin: Date; } }Any keys not defined in this interface will be treated as
any.Then when you access
Astro.sessionin your components, any defined keys will be typed correctly:--- const user = await Astro.session.get('user'); // ^? const: user: { id: string; email: string; } | undefined const something = await Astro.session.get('something'); // ^? const: something: any Astro.session.set('user', 1); // ^? Argument of type 'number' is not assignable to parameter of type '{ id: string; email: string; }'. ---See the experimental session docs for more information.
-
#13330
5e7646eThanks @ematipico! - Fixes an issue with the conditional rendering of scripts.This change updates a v5.0 breaking change when
experimental.directRenderScriptbecame the default script handling behavior.If you have already successfully upgraded to Astro v5, you may need to review your script tags again and make sure they still behave as desired after this release. See the v5 Upgrade Guide for more details.
5.4.0
Minor Changes
-
#12052
5be12b2Thanks @Fryuni! - Exposes extra APIs for scripting and testing.Config helpers
Two new helper functions exported from
astro/config:mergeConfig()allows users to merge partially defined Astro configurations on top of a base config while following the merge rules ofupdateConfig()available for integrations.validateConfig()allows users to validate that a given value is a valid Astro configuration and fills in default values as necessary.
These helpers are particularly useful for integration authors and for developers writing scripts that need to manipulate Astro configurations programmatically.
Programmatic build
The
buildAPI now receives a second optionalBuildOptionsargument where users can specify:devOutput(defaultfalse): output a development-based build similar to code transformed inastro dev.teardownCompiler(defaulttrue): teardown the compiler WASM instance after build.
These options provide more control when running Astro builds programmatically, especially for testing scenarios or custom build pipelines.
-
#13278
4a43c4bThanks @ematipico! - Adds a new configuration optionserver.allowedHostsand CLI option--allowed-hosts.Now you can specify the hostnames that the dev and preview servers are allowed to respond to. This is useful for allowing additional subdomains, or running the dev server in a web container.
allowedHostschecks the Host header on HTTP requests from browsers and if it doesn't match, it will reject the request to prevent CSRF and XSS attacks.astro dev --allowed-hosts=foo.bar.example.com,bar.example.comastro preview --allowed-hosts=foo.bar.example.com,bar.example.com// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ server: { allowedHosts: ['foo.bar.example.com', 'bar.example.com'], }, });This feature is the same as Vite's
server.allowHostsconfiguration. -
#13254
1e11f5eThanks @p0lyw0lf! - Adds the ability to process and optimize remote images in Markdown filesPreviously, Astro only allowed local images to be optimized when included using
![]()syntax in plain Markdown files. Astro's image service could only display remote images without any processing.Now, Astro's image service can also optimize remote images written in standard Markdown syntax. This allows you to enjoy the benefits of Astro's image processing when your images are stored externally, for example in a CMS or digital asset manager.
No additional configuration is required to use this feature! Any existing remote images written in Markdown will now automatically be optimized. To opt-out of this processing, write your images in Markdown using the HTML
<img>tag instead. Note that images located in yourpublic/folder are still never processed.
Patch Changes
-
#13256
509fa67Thanks @p0lyw0lf! - Adds experimental responsive image support in MarkdownPreviously, the
experimental.responsiveImagesfeature could only provide responsive images when using the<Image />and<Picture />components.Now, images written with the
![]()Markdown syntax in Markdown and MDX files will generate responsive images by default when using this experimental feature.To try this experimental feature, set
experimental.responsiveImagesto true in yourastro.config.mjsfile:{ experimental: { responsiveImages: true, }, }Learn more about using this feature in the experimental responsive images feature reference.
For a complete overview, and to give feedback on this experimental API, see the Responsive Images RFC.
-
#13323
80926faThanks @ematipico! - Updatesesbuildandviteto the latest to avoid false positives audits warnings caused byesbuild. -
#13313
9e7c71dThanks @martrapp! - Fixes an issue where a form field named "attributes" shadows the form.attributes property. -
#12052
5be12b2Thanks @Fryuni! - Fixes incorrect config update when callingupdateConfigfromastro:build:setuphook.The function previously called a custom update config function made for merging an Astro config. Now it calls the appropriate
mergeConfig()utility exported by Vite that updates functional options correctly. -
#13303
5f72a58Thanks @ematipico! - Fixes an issue where the dev server was applying second decoding of the URL of the incoming request, causing issues for certain URLs. -
Updated dependencies [
1e11f5e,1e11f5e]:- @astrojs/internal-helpers@0.6.0
- @astrojs/markdown-remark@6.2.0
5.3.1
Patch Changes
-
#13233
32fafebThanks @joshmkennedy! - Ensures consistent behaviour ofAstro.rewrite/ctx.rewritewhen usingbaseandtrailingSlashoptions. -
#13003
ea79054Thanks @chaegumi! - Fixes a bug that caused thevite.basevalue to be ignored when runningastro dev -
#13299
2e1321eThanks @bluwy! - Usestinyglobbyfor globbing files -
#13233
32fafebThanks @joshmkennedy! - Ensures thatAstro.url/ctx.urlis correctly updated with thebasepath after rewrites.This change fixes an issue where
Astro.url/ctx.urldid not include the configured base path after Astro.rewrite was called. Now, the base path is correctly reflected in Astro.url.Previously, any rewrites performed through
Astro.rewrite/ctx.rewritefailed to append the base path toAstro.url/ctx.rewrite, which could lead to incorrect URL handling in downstream logic. By fixing this, we ensure that all routes remain consistent and predictable after a rewrite.If you were relying on the work around of including the base path in astro.rewrite you can now remove it from the path.
5.3.0
Minor Changes
-
#13210
344e9bcThanks @VitaliyR! - HandleHEADrequests to an endpoint when a handler is not defined.If an endpoint defines a handler for
GET, but does not define a handler forHEAD, Astro will call theGEThandler and return the headers and status but an empty body. -
#13195
3b66955Thanks @MatthewLymer! - Improves SSR performance for synchronous components by avoiding the use of Promises. With this change, SSR rendering of on-demand pages can be up to 4x faster. -
#13145
8d4e566Thanks @ascorbic! - Adds support for adapters auto-configuring experimental session storage drivers.Adapters can now configure a default session storage driver when the
experimental.sessionflag is enabled. If a hosting platform has a storage primitive that can be used for session storage, the adapter can automatically configure the session storage using that driver. This allows Astro to provide a more seamless experience for users who want to use sessions without needing to manually configure the session storage.
Patch Changes
-
#13145
8d4e566Thanks @ascorbic! - ⚠️ BREAKING CHANGE FOR EXPERIMENTAL SESSIONS ONLY ⚠️Changes the
experimental.sessionoption to a boolean flag and moves session config to a top-level value. This change is to allow the new automatic session driver support. You now need to separately enable theexperimental.sessionflag, and then configure the session driver using the top-levelsessionkey if providing manual configuration.defineConfig({ // ... experimental: { - session: { - driver: 'upstash', - }, + session: true, }, + session: { + driver: 'upstash', + }, });You no longer need to configure a session driver if you are using an adapter that supports automatic session driver configuration and wish to use its default settings.
defineConfig({ adapter: node({ mode: "standalone", }), experimental: { - session: { - driver: 'fs', - cookie: 'astro-cookie', - }, + session: true, }, + session: { + cookie: 'astro-cookie', + }, });However, you can still manually configure additional driver options or choose a non-default driver to use with your adapter with the new top-level
sessionconfig option. For more information, see the experimental session docs. -
#13101
2ed67d5Thanks @corneliusroemer! - Fixes a bug whereHEADandOPTIONSrequests for non-prerendered pages were incorrectly rejected with 403 FORBIDDEN
5.2.6
Patch Changes
-
#13188
7bc8256Thanks @ematipico! - Fixes the wording of the an error message -
#13205
9d56602Thanks @ematipico! - Fixes and issue where a server island component returns 404 whenbaseis configured in i18n project. -
#13212
fb38840Thanks @joshmkennedy! - An additional has been added during the build command to add clarity around output and buildOutput. -
#13213
6bac644Thanks @joshmkennedy! - Allows readonly arrays to be passed to thepaginate()function
5.2.5
Patch Changes
-
#13133
e76aa83Thanks @ematipico! - Fixes a bug where Astro was failing to build an external redirect when the middleware was triggered -
#13119
ac43580Thanks @Hacksore! - Adds extra guidance in the terminal when using theastro add tailwindCLI commandNow, users are given a friendly reminder to import the stylesheet containing their Tailwind classes into any pages where they want to use Tailwind. Commonly, this is a shared layout component so that Tailwind styling can be used on multiple pages.
5.2.4
Patch Changes
-
#13130
b71bd10Thanks @ascorbic! - Fixes a bug that caused duplicate slashes inside query params to be collapsed -
#13131
d60c742Thanks @ascorbic! - Ignores trailing slashes for endpoints with file extensions in the route -
Updated dependencies [
b71bd10]:- @astrojs/internal-helpers@0.5.1
5.2.3
Patch Changes
-
#13113
3a26e45Thanks @unprintable123! - Fixes the bug that rewrite will pass encoded url to the dynamic routing and cause params mismatch. -
#13111
23978ddThanks @ascorbic! - Fixes a bug that caused injected endpoint routes to return not found when trailingSlash was set to always -
#13112
0fa5c82Thanks @ematipico! - Fixes a bug where the i18n middleware was blocking a server island request when theprefixDefaultLocaleoption is set totrue
5.2.2
Patch Changes
- #13106
187c4d3Thanks @ascorbic! - Fixes a bug that caused peer dependency errors when runningastro add tailwind
5.2.1
Patch Changes
- #13095
740eb60Thanks @ascorbic! - Fixes a bug that caused some dev server asset requests to return 404 when trailingSlash was set to "always"
5.2.0
Minor Changes
-
#12994
5361755Thanks @ascorbic! - Redirects trailing slashes for on-demand pagesWhen the
trailingSlashoption is set toalwaysornever, on-demand rendered pages will now redirect to the correct URL when the trailing slash doesn't match the configuration option. This was previously the case for static pages, but now works for on-demand pages as well.Now, it doesn't matter whether your visitor navigates to
/about/,/about, or even/about///. In production, they'll always end up on the correct page. For GET requests, the redirect will be a 301 (permanent) redirect, and for all other request methods, it will be a 308 (permanent, and preserve the request method) redirect.In development, you'll see a helpful 404 page to alert you of a trailing slash mismatch so you can troubleshoot routes.
-
#12979
e621712Thanks @ematipico! - Adds support for redirecting to external sites with theredirectsconfiguration option.Now, you can redirect routes either internally to another path or externally by providing a URL beginning with
httporhttps:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ redirects: { '/blog': 'https://example.com/blog', '/news': { status: 302, destination: 'https://example.com/news', }, }, }); -
#13084
0f3be31Thanks @ematipico! - Adds a new experimental virtual moduleastro:configthat exposes a type-safe subset of yourastro.config.mjsconfigurationThe virtual module exposes two sub-paths for controlled access to your configuration:
astro:config/client: exposes config information that is safe to expose to the client.astro:config/server: exposes additional information that is safe to expose to the server, such as file/dir paths.
To enable this new virtual module, add the
experimental.serializeManifestfeature flag to your Astro config:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { serializeManifest: true, }, });Then, you can access the module in any file inside your project to import and use values from your Astro config:
// src/utils.js import { trailingSlash } from 'astro:config/client'; function addForwardSlash(path) { if (trailingSlash === 'always') { return path.endsWith('/') ? path : path + '/'; } else { return path; } }For a complete overview, and to give feedback on this experimental API, see the Serialized Manifest RFC.
Patch Changes
-
#13049
2ed4bd9Thanks @florian-lefebvre! - Updatesastro add tailwindto add the@tailwindcss/viteplugin instead of the@astrojs/tailwindintegration -
#12994
5361755Thanks @ascorbic! - Returns a more helpful 404 page in dev if there is a trailing slash mismatch between the route requested and thetrailingSlashconfiguration -
#12666
037495dThanks @Thodor12! - Added additional generated typings for the content layer -
Updated dependencies [
5361755,db252e0]:- @astrojs/internal-helpers@0.5.0
- @astrojs/markdown-remark@6.1.0
5.1.10
Patch Changes
-
#13058
1a14b53Thanks @ascorbic! - Fixes broken type declaration -
#13059
e36837fThanks @ascorbic! - Fixes a bug that caused tsconfig path aliases to break if there was more than one wildcard pattern -
#13045
c7f1366Thanks @mtwilliams-code! - Fixes a bug where the some utility functions of theastro:i18nvirtual module would return an incorrect result whentrailingSlashis set tonever
5.1.9
Patch Changes
-
#12986
8911bdaThanks @wetheredge! - Updates types and dev toolbar for ARIA 1.2 attributes and roles -
#12892
8f520f1Thanks @louisescher! - Adds a more descriptive error when a content collection entry has an invalid ID. -
#13031
f576519Thanks @florian-lefebvre! - Updates the server islands encoding logic to only escape the script end tag open delimiter and opening HTML comment syntax -
#13026
1d272f6Thanks @ascorbic! - Fixes a regression that prevented the import of Markdown files as raw text or URLs.
5.1.8
Patch Changes
-
#12998
9ce0038Thanks @Kynson! - Fixes the issue that audit incorrectly flag images as above the fold when the scrolling container is not body -
#12990
2e12f1dThanks @ascorbic! - Fixes a bug that caused references to be incorrectly reported as invalid -
#12984
2d259cfThanks @ascorbic! - Fixes a bug in dev where files would stop being watched if the Astro config file was edited -
#12984
2d259cfThanks @ascorbic! - Fixes a bug where the content layer would use an outdated version of the Astro config if it was edited in dev -
#12982
429aa75Thanks @bluwy! - Fixes an issue where server islands do not work in projects that use an adapter but only have prerendered pages. If an adapter is added, the server island endpoint will now be added by default. -
#12995
78fd73aThanks @florian-lefebvre! - Fixes a case whereastro:actionstypes would not work when usingsrc/actions.ts -
#12733
bbf1d88Thanks @ascorbic! - Fixes a bug that caused the dev server to return an error if requesting "//" -
#13001
627aec3Thanks @ascorbic! - Fixes a bug that caused Astro to attempt to inject environment variables into non-source files, causing performance problems and broken builds
5.1.7
Patch Changes
-
#12361
3d89e62Thanks @LunaticMuch! - Upgrades theesbuildversion to matchvite -
#12980
1a026afThanks @florian-lefebvre! - Fixes a case where setting the status of a page to404in development would show the default 404 page (or custom one if provided) instead of using the current page -
#12182
c30070bThanks @braden-w! - Improves matching of 404 and 500 routes -
Updated dependencies [
3d89e62]:- @astrojs/markdown-remark@6.0.2
5.1.6
Patch Changes
-
#12956
3aff68aThanks @kaytwo! - Removes encryption of empty props to allow server island cacheability -
#12977
80067c0Thanks @florian-lefebvre! - Fixes a case where accessingastro:envAPIs orimport.meta.envinside the content config file would not work -
#12839
57be349Thanks @mtwilliams-code! - Fix Astro.currentLocale returning the incorrect locale when using fallback rewrites in SSR mode -
#12962
4b7a2ceThanks @ascorbic! - Skips updating content layer files if content is unchanged -
#12942
f00c2ddThanks @liruifengv! - Improves the session error messages -
#12966
d864e09Thanks @ascorbic! - Ensures old content collection entry is deleted if a markdown frontmatter slug is changed in dev
5.1.5
Patch Changes
-
#12934
673a518Thanks @ematipico! - Fixes a regression where the Astro Container didn't work during the build, usingpnpm -
#12955
db447f2Thanks @martrapp! - Lets TypeScript know about the "blocking" and "disabled" attributes of the<link>element. -
#12922
faf74afThanks @adamchal! - Improves performance of static asset generation by fixing a bug that caused image transforms to be performed serially. This fix ensures that processing uses all CPUs when running in a multi-core environment. -
#12947
3c2292fThanks @ascorbic! - Fixes a bug that caused empty content collections when running dev with NODE_ENV set
5.1.4
Patch Changes
-
#12927
ad2a752Thanks @ematipico! - Fixes a bug where Astro attempted to decode a request URL multiple times, resulting in an unexpected behaviour when decoding the character% -
#12912
0c0c66bThanks @florian-lefebvre! - Improves the config error for invalid combinations ofcontextandaccessproperties underenv.schema -
#12935
3d47e6bThanks @AirBorne04! - Fixes an issue whereAstro.localscoming from an adapter weren't available in the404.astro, when using theastro devcommand, -
#12925
44841fcThanks @ascorbic! - Ensures image styles are not imported unless experimental responsive images are enabled -
#12926
8e64bb7Thanks @oliverlynch! - Improves remote image cache efficiency by separating image data and metadata into a binary and sidecar JSON file. -
#12920
8b9d530Thanks @bluwy! - Processes markdown with empty body as remark and rehype plugins may add additional content or frontmatter -
#12918
fd12a26Thanks @lameuler! - Fixes a bug where the logged output path does not match the actual output path when usingbuild.format: 'preserve' -
#12676
2ffc0fcThanks @koyopro! - Allows configuring Astro modules TypeScript compilation with thevite.esbuildconfig -
#12938
dbb04f3Thanks @ascorbic! - Fixes a bug where content collections would sometimes appear empty when first running astro dev -
#12937
30edb6dThanks @ematipico! - Fixes a bug where users could useAstro.request.headersduring a rewrite inside prerendered routes. This an invalid behaviour, and now Astro will show a warning if this happens. -
#12937
30edb6dThanks @ematipico! - Fixes an issue where the use ofAstro.rewritewould trigger the invalid use ofAstro.request.headers
5.1.3
Patch Changes
-
#12877
73a0788Thanks @bluwy! - Fixes sourcemap warning generated by theastro:server-islandsVite plugin -
#12906
2d89492Thanks @ascorbic! - Fixes a bug that caused pages that return an empty array from getStaticPath to match every path -
011fa0fThanks @florian-lefebvre! - Fixes a case whereastro:contenttypes would be erased when restarting the dev server -
#12907
dbf1275Thanks @florian-lefebvre! - Fixes a regression around the server islands route, which was not passed to the adaptersastro:build:donehook -
#12818
579bd93Thanks @ascorbic! - Fixes race condition where dev server would attempt to load collections before the content had loaded -
#12883
fbac92fThanks @kaytwo! - Fixes a bug where responses can be returned before session data is saved -
#12815
3acc654Thanks @ericswpark! - Some non-index files that were incorrectly being treated as index files are now excluded -
#12884
d7e97a7Thanks @ascorbic! - Addsrender()to stub content types -
#12883
fbac92fThanks @kaytwo! - Fixes a bug where session data could be corrupted if it is changed after calling .set() -
#12827
7b5dc6fThanks @sinskiy! - Fixes an issue when crawlers try to index Server Islands thinking that Server Islands are pages
5.1.2
Patch Changes
-
#12798
7b0cb85Thanks @ascorbic! - Improves warning logs for invalid content collection configuration -
#12781
96c4b92Thanks @ascorbic! - Fixes a regression that causeddefault()to not work withreference() -
#12820
892dd9fThanks @ascorbic! - Fixes a bug that caused cookies to not be deleted when destroying a session -
#12864
440d8a5Thanks @kaytwo! - Fixes a bug where the session ID wasn't correctly regenerated -
#12768
524c855Thanks @ematipico! - Fixes an issue where Astro didn't print error logs when Astro Islands were used in incorrect cases. -
#12814
f12f111Thanks @ematipico! - Fixes an issue where Astro didn't log anything in case a file isn't created during the build. -
#12875
e109002Thanks @ascorbic! - Fixes a bug in emulated legacy collections where the entry passed to the getCollection filter function did not include the legacy entry fields. -
#12768
524c855Thanks @ematipico! - Fixes an issue where Astro was printing the incorrect output format when running theastro buildcommand -
#12810
70a9f0bThanks @louisescher! - Fixes server islands failing to check content-type header under certain circumstancesSometimes a reverse proxy or similar service might modify the content-type header to include the charset or other parameters in the media type of the response. This previously wasn't handled by the client-side server island script and thus removed the script without actually placing the requested content in the DOM. This fix makes it so the script checks if the header starts with the proper content type instead of exactly matching
text/html, so the following will still be considered a valid header:text/html; charset=utf-8 -
#12816
7fb2184Thanks @ematipico! - Fixes an issue where an injected route entrypoint wasn't correctly marked because the resolved file path contained a query parameter.This fixes some edge case where some injected entrypoint were not resolved when using an adapter.
5.1.1
Patch Changes
-
#12782
f3d8385Thanks @fhiromasa! - update comment in packages/astro/src/types/public/common.ts -
#12789
f632b94Thanks @ascorbic! - Pass raw frontmatter to remark plugins in glob loader -
#12799
739dbfbThanks @ascorbic! - Upgrades Vite to pin esbuild
5.1.0
Minor Changes
-
#12441
b4fec3cThanks @ascorbic! - Adds experimental session supportSessions are used to store user state between requests for server-rendered pages, such as login status, shopping cart contents, or other user-specific data.
--- export const prerender = false; // Not needed in 'server' mode const cart = await Astro.session.get('cart'); --- <a href="/checkout">🛒 {cart?.length ?? 0} items</a>Sessions are available in on-demand rendered/SSR pages, API endpoints, actions and middleware. To enable session support, you must configure a storage driver.
If you are using the Node.js adapter, you can use the
fsdriver to store session data on the filesystem:// astro.config.mjs { adapter: node({ mode: 'standalone' }), experimental: { session: { // Required: the name of the unstorage driver driver: "fs", }, }, }If you are deploying to a serverless environment, you can use drivers such as
redis,netlify-blobs,vercel-kv, orcloudflare-kv-bindingand optionally pass additional configuration options.For more information, including using the session API with other adapters and a full list of supported drivers, see the docs for experimental session support. For even more details, and to leave feedback and participate in the development of this feature, the Sessions RFC.
-
#12426
3dc02c5Thanks @oliverlynch! - Improves asset caching of remote imagesAstro will now store entity tags and the Last-Modified date for cached remote images and use them to revalidate the cache when it goes stale.
-
#12721
c9d5110Thanks @florian-lefebvre! - Adds a newgetActionPath()helper available fromastro:actionsAstro 5.1 introduces a new helper function,
getActionPath()to give you more flexibility when calling your action.Calling
getActionPath()with your action returns its URL path so you can make afetch()request with custom headers, or use your action with an API such asnavigator.sendBeacon(). Then, you can handle the custom-formatted returned data as needed, just as if you had called an action directly.This example shows how to call a defined
likeaction passing theAuthorizationheader and thekeepaliveoption:<script> // src/components/my-component.astro import { actions, getActionPath } from 'astro:actions'; await fetch(getActionPath(actions.like), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Bearer YOUR_TOKEN', }, body: JSON.stringify({ id: 'YOUR_ID' }), keepalive: true, }); </script>This example shows how to call the same
likeaction using thesendBeaconAPI:<script> // src/components/my-component.astro import { actions, getActionPath } from 'astro:actions'; navigator.sendBeacon( getActionPath(actions.like), new Blob([JSON.stringify({ id: 'YOUR_ID' })], { type: 'application/json', }), ); </script>
Patch Changes
-
#12786
e56af4aThanks @ematipico! - Fixes an issue where Astro i18n didn't properly show the 404 page when using fallback and the optionprefixDefaultLocaleset totrue. -
#12758
483da89Thanks @delucis! - Adds types for?url&inlineand?url&no-inlineimport queries added in Vite 6 -
#12763
8da2318Thanks @rbsummers! - Fixed changes to vite configuration made in the astro:build:setup integration hook having no effect when target is "client" -
#12767
36c1e06Thanks @ascorbic! - Clears the content layer cache when the Astro config is changed
5.0.9
Patch Changes
5.0.8
Patch Changes
5.0.7
Patch Changes
5.0.6
Patch Changes
-
#12597
564ac6cThanks @florian-lefebvre! - Fixes an issue where image and server islands routes would not be passed to theastro:routes:resolvedhook during builds -
#12718
ccc5ad1Thanks @ematipico! - Fixes an issue where Astro couldn't correctly handle i18n fallback when using the i18n middleware -
#12728
ee66a45Thanks @argyleink! - Adds type support for theclosedbyattribute for<dialog>elements -
#12709
e3bfd93Thanks @mtwilliams-code! - Fixes a bug where Astro couldn't correctly parseparamsandpropswhen receiving i18n fallback URLs -
#12657
14dffccThanks @darkmaga! - Trailing slash support for actions -
#12715
029661dThanks @ascorbic! - Fixes a bug that caused errors in dev when editing sites with large numbers of MDX pages -
#12729
8b1cecdThanks @JoeMorgan! - "Addedinertto htmlBooleanAttributes" -
#12726
7c7398cThanks @florian-lefebvre! - Fixes a case where failing content entries inastro checkwould not be surfaced
5.0.5
Patch Changes
-
#12705
0d1eab5Thanks @ascorbic! - Fixes a bug where MDX files with certain characters in the name would cause builds to fail -
#12707
2aaed2dThanks @ematipico! - Fixes a bug where the middleware was incorrectly imported during the build -
#12697
1c4a032Thanks @ascorbic! - Fix a bug that caused builds to fail if an image had a quote mark in its name -
#12694
495f46bThanks @ematipico! - Fixes a bug where the experimental featureexperimental.svgwas incorrectly used when generating ESM images -
#12658
3169593Thanks @jurajkapsz! - Fixes astro info copy to clipboard process not returning to prompt in certain cases. -
#12712
b01c74aThanks @ascorbic! - Fixes a bug which misidentified pages as markdown if a query string ended in a markdown extension
5.0.4
Patch Changes
-
#12653
e21c7e6Thanks @sarah11918! - Updates a reference in an error message -
#12585
a9373c0Thanks @florian-lefebvre! - Fixes a case whereprocess.envwould be frozen despite changes made to environment variables in development -
#12695
a203d5dThanks @ascorbic! - Throws a more helpful error when images are missing -
Updated dependencies [
f13417b,87231b1,a71e9b9]:- @astrojs/markdown-remark@6.0.1
5.0.3
Patch Changes
-
#12645
8704c54Thanks @sarah11918! - Updates some reference links in error messages for new v5 docs. -
#12641
48ca399Thanks @ascorbic! - Fixes a bug whereastro info --copywasn't working correctly onmacOSsystems. -
#12461
62939adThanks @kyr0! - Removes the misleading log message telling that a custom renderer is not recognized while it clearly is and works. -
#12642
ff18b9cThanks @ematipico! - Provides more information when logging a warning for accessingAstro.request.headersin prerendered pages -
#12634
03958d9Thanks @delucis! - Improves error message formatting for user config and content collection frontmatter -
#12547
6b6e18dThanks @mtwilliams-code! - Fixes a bug where URL search parameters weren't passed when using the i18nfallbackfeature. -
#12449
e6b8017Thanks @apatel369! - Fixes an issue where the customassetFileNamesconfiguration caused assets to be incorrectly moved to the server directory instead of the client directory, resulting in 404 errors when accessed from the client side. -
#12518
e216250Thanks @ematipico! - Fixes an issue where SSR error pages would return duplicated custom headers. -
#12625
74bfad0Thanks @ematipico! - Fixes an issue where theexperimental.svghad incorrect type, resulting in some errors in the editors. -
#12631
dec0305Thanks @ascorbic! - Fixes a bug where the class attribute was rendered twice on the image component -
#12623
0e4fecbThanks @ascorbic! - Correctly handles images in content collections with uppercase file extensions -
#12633
8a551c1Thanks @bluwy! - Cleans up content layer sync during builds and programmaticsync()calls -
#12640
22e405aThanks @ascorbic! - Fixes a bug that caused content collections to be returned empty when run in a test environment -
#12613
306c9f9Thanks @matthewp! - Fix use of cloned requests in middleware with clientAddressWhen using
context.clientAddressorAstro.clientAddressAstro looks up the address in a hidden property. Cloning a request can cause this hidden property to be lost.The fix is to pass the address as an internal property instead, decoupling it from the request.
5.0.2
Patch Changes
5.0.1
Patch Changes
5.0.0
Major Changes
-
#11798
e9e2139Thanks @matthewp! - Unflag globalRoutePriorityThe previously experimental feature
globalRoutePriorityis now the default in Astro 5.This was a refactoring of route prioritization in Astro, making it so that injected routes, file-based routes, and redirects are all prioritized using the same logic. This feature has been enabled for all Starlight projects since it was added and should not affect most users.
-
#11864
ee38b3aThanks @ematipico! - ### [changed]:entryPointtype inside the hookastro:build:ssrIn Astro v4.x, theentryPointtype wasRouteData.Astro v5.0 the
entryPointtype isIntegrationRouteData, which contains a subset of theRouteDatatype. The fieldsisIndexandfallbackRouteswere removed.What should I do?
Update your adapter to change the type of
entryPointfromRouteDatatoIntegrationRouteData.-import type {RouteData} from 'astro'; +import type {IntegrationRouteData} from "astro" -function useRoute(route: RouteData) { +function useRoute(route: IntegrationRouteData) { } -
#12524
9f44019Thanks @bluwy! - Bumps Vite to ^6.0.1 and handles its breaking changes -
#10742
b6fbdaaThanks @ematipico! - The lowest version of Node supported by Astro is now Node v18.17.1 and higher. -
#11916
46ea29fThanks @bluwy! - Updates how thebuild.clientandbuild.serveroption values get resolved to match existing documentation. With this fix, the option values will now correctly resolve relative to theoutDiroption. So ifoutDiris set to./dist/nested/, then by default:build.clientwill resolve to<root>/dist/nested/client/build.serverwill resolve to<root>/dist/nested/server/
Previously the values were incorrectly resolved:
build.clientwas resolved to<root>/dist/nested/dist/client/build.serverwas resolved to<root>/dist/nested/dist/server/
If you were relying on the previous build paths, make sure that your project code is updated to the new build paths.
-
#11982
d84e444Thanks @Princesseuh! - Adds a default exclude and include value to the tsconfig presets.{projectDir}/distis now excluded by default, and{projectDir}/.astro/types.d.tsand{projectDir}/**/*are included by default.Both of these options can be overridden by setting your own values to the corresponding settings in your
tsconfig.jsonfile. -
#11861
3ab3b4eThanks @bluwy! - Cleans up Astro-specific metadata attached tovfile.datain Remark and Rehype plugins. Previously, the metadata was attached in different locations with inconsistent names. The metadata is now renamed as below:vfile.data.__astroHeadings->vfile.data.astro.headingsvfile.data.imagePaths->vfile.data.astro.imagePaths
The types of
imagePathshas also been updated fromSet<string>tostring[]. Thevfile.data.astro.frontmattermetadata is left unchanged.While we don't consider these APIs public, they can be accessed by Remark and Rehype plugins that want to re-use Astro's metadata. If you are using these APIs, make sure to access them in the new locations.
-
#11987
bf90a53Thanks @florian-lefebvre! - Thelocalsobject can no longer be overriddenMiddleware, API endpoints, and pages can no longer override the
localsobject in its entirety. You can still append values onto the object, but you can not replace the entire object and delete its existing values.If you were previously overwriting like so:
ctx.locals = { one: 1, two: 2, };This can be changed to an assignment on the existing object instead:
Object.assign(ctx.locals, { one: 1, two: 2, }); -
#11908
518433eThanks @Princesseuh! - Theimage.endpointconfig now allow customizing the route of the image endpoint in addition to the entrypoint. This can be useful in niche situations where the default route/_imageconflicts with an existing route or your local server setup.import { defineConfig } from 'astro/config'; defineConfig({ image: { endpoint: { route: '/image', entrypoint: './src/image_endpoint.ts', }, }, }); -
#12008
5608338Thanks @Princesseuh! - Welcome to the Astro 5 beta! This release has no changes from the latest alpha of this package, but it does bring us one step closer to the final, stable release.Starting from this release, no breaking changes will be introduced unless absolutely necessary.
To learn how to upgrade, check out the Astro v5.0 upgrade guide in our beta docs site.
-
#11679
ea71b90Thanks @florian-lefebvre! - Theastro:envfeature introduced behind a flag in v4.10.0 is no longer experimental and is available for general use. If you have been waiting for stabilization before usingastro:env, you can now do so.This feature lets you configure a type-safe schema for your environment variables, and indicate whether they should be available on the server or the client.
To configure a schema, add the
envoption to your Astro config and define your client and server variables. If you were previously using this feature, please remove the experimental flag from your Astro config and move your entireenvconfiguration unchanged to a top-level option.import { defineConfig, envField } from 'astro/config'; export default defineConfig({ env: { schema: { API_URL: envField.string({ context: 'client', access: 'public', optional: true }), PORT: envField.number({ context: 'server', access: 'public', default: 4321 }), API_SECRET: envField.string({ context: 'server', access: 'secret' }), }, }, });You can import and use your defined variables from the appropriate
/clientor/servermodule:--- import { API_URL } from 'astro:env/client'; import { API_SECRET_TOKEN } from 'astro:env/server'; const data = await fetch(`${API_URL}/users`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_SECRET_TOKEN}`, }, }); --- <script> import { API_URL } from 'astro:env/client'; fetch(`${API_URL}/ping`); </script>Please see our guide to using environment variables for more about this feature.
-
#11806
f7f2338Thanks @Princesseuh! - Removes theassetsproperty onsupportedAstroFeaturesfor adapters, as it did not reflect reality properly in many cases.Now, relating to assets, only a single
sharpImageServiceproperty is available, determining if the adapter is compatible with the built-in sharp image service. -
#11864
ee38b3aThanks @ematipico! - ### [changed]:routestype inside the hookastro:build:doneIn Astro v4.x, theroutestype wasRouteData.Astro v5.0 the
routestype isIntegrationRouteData, which contains a subset of theRouteDatatype. The fieldsisIndexandfallbackRouteswere removed.What should I do?
Update your adapter to change the type of
routesfromRouteDatatoIntegrationRouteData.-import type {RouteData} from 'astro'; +import type {IntegrationRouteData} from "astro" -function useRoute(route: RouteData) { +function useRoute(route: IntegrationRouteData) { } -
#11941
b6a5f39Thanks @Princesseuh! - Merges theoutput: 'hybrid'andoutput: 'static'configurations into one single configuration (now called'static') that works the same way as the previoushybridoption.It is no longer necessary to specify
output: 'hybrid'in your Astro config to use server-rendered pages. The newoutput: 'static'has this capability included. Astro will now automatically provide the ability to opt out of prerendering in your static site with no change to youroutputconfiguration required. Any page route or endpoint can includeexport const prerender = falseto be server-rendered, while the rest of your site is statically-generated.If your project used hybrid rendering, you must now remove the
output: 'hybrid'option from your Astro config as it no longer exists. However, no other changes to your project are required, and you should have no breaking changes. The previous'hybrid'behavior is now the default, under a new name'static'.If you were using the
output: 'static'(default) option, you can continue to use it as before. By default, all of your pages will continue to be prerendered and you will have a completely static site. You should have no breaking changes to your project.import { defineConfig } from "astro/config"; export default defineConfig({ - output: 'hybrid', });An adapter is still required to deploy an Astro project with any server-rendered pages. Failure to include an adapter will result in a warning in development and an error at build time.
-
#11788
7c0ccfcThanks @ematipico! - Updates the default value ofsecurity.checkOrigintotrue, which enables Cross-Site Request Forgery (CSRF) protection by default for pages rendered on demand.If you had previously configured
security.checkOrigin: true, you no longer need this set in your Astro config. This is now the default and it is safe to remove.To disable this behavior and opt out of automatically checking that the “origin” header matches the URL sent by each request, you must explicitly set
security.checkOrigin: false:export default defineConfig({ + security: { + checkOrigin: false + } }) -
#11825
560ef15Thanks @bluwy! - Updates internal Shiki rehype plugin to highlight code blocks as hast (using Shiki'scodeToHast()API). This allows a more direct Markdown and MDX processing, and improves the performance when building the project, but may cause issues with existing Shiki transformers.If you are using Shiki transformers passed to
markdown.shikiConfig.transformers, you must make sure they do not use thepostprocesshook as it no longer runs on code blocks in.mdand.mdxfiles. (See the Shiki documentation on transformer hooks for more information).Code blocks in
.mdocfiles and<Code />component do not use the internal Shiki rehype plugin and are unaffected. -
#11826
7315050Thanks @matthewp! - Deprecate Astro.globThe
Astro.globfunction has been deprecated in favor of Content Collections andimport.meta.glob.- If you want to query for markdown and MDX in your project, use Content Collections.
- If you want to query source files in your project, use
import.meta.glob(https://vitejs.dev/guide/features.html#glob-import).
Also consider using glob packages from npm, like fast-glob, especially if statically generating your site, as it is faster for most use-cases.
The easiest path is to migrate to
import.meta.globlike so:- const posts = Astro.glob('./posts/*.md'); + const posts = Object.values(import.meta.glob('./posts/*.md', { eager: true })); -
#12268
4e9a3acThanks @ematipico! - The commandastro add vercelnow updates the configuration file differently, and adds@astrojs/vercelas module to import.This is a breaking change because it requires the version
8.*of@astrojs/vercel. -
#11741
6617491Thanks @bluwy! - Removes internal JSX handling and moves the responsibility to the@astrojs/mdxpackage directly. The following exports are also now removed:astro/jsx/babel.jsastro/jsx/component.jsastro/jsx/index.jsastro/jsx/renderer.jsastro/jsx/server.jsastro/jsx/transform-options.js
If your project includes
.mdxfiles, you must upgrade@astrojs/mdxto the latest version so that it doesn't rely on these entrypoints to handle your JSX. -
#11782
9a2aaa0Thanks @Princesseuh! - Makes thecompiledContentproperty of Markdown content an async function, this change should fix underlying issues where sometimes when using a custom image service and images inside Markdown, Node would exit suddenly without any error message.--- import * as myPost from "../post.md"; - const content = myPost.compiledContent(); + const content = await myPost.compiledContent(); --- <Fragment set:html={content} /> -
#11819
2bdde80Thanks @bluwy! - Updates the Astro config loading flow to ignore processing locally-linked dependencies with Vite (e.g.npm link, in a monorepo, etc). Instead, they will be normally imported by the Node.js runtime the same way as other dependencies fromnode_modules.Previously, Astro would process locally-linked dependencies which were able to use Vite features like TypeScript when imported by the Astro config file.
However, this caused confusion as integration authors may test against a package that worked locally, but not when published. This method also restricts using CJS-only dependencies because Vite requires the code to be ESM. Therefore, Astro's behaviour is now changed to ignore processing any type of dependencies by Vite.
In most cases, make sure your locally-linked dependencies are built to JS before running the Astro project, and the config loading should work as before.
-
#11827
a83e362Thanks @matthewp! - Prevent usage ofastro:contentin the clientUsage of
astro:contentin the client has always been discouraged because it leads to all of your content winding up in your client bundle, and can possibly leaks secrets.This formally makes doing so impossible, adding to the previous warning with errors.
In the future Astro might add APIs for client-usage based on needs.
-
#11979
423dfc1Thanks @bluwy! - Bumpsvitedependency to v6.0.0-beta.2. The version is pinned and will be updated as new Vite versions publish to prevent unhandled breaking changes. For the full list of Vite-specific changes, see its changelog. -
#11859
3804711Thanks @florian-lefebvre! - Changes the defaulttsconfig.jsonwith better defaults, and makessrc/env.d.tsoptionalAstro's default
tsconfig.jsonin starter examples has been updated to include generated types and exclude your build output. This means thatsrc/env.d.tsis only necessary if you have added custom type declarations or if you're not using atsconfig.jsonfile.Additionally, running
astro syncno longer creates, nor updates,src/env.d.tsas it is not required for type-checking standard Astro projects.To update your project to Astro's recommended TypeScript settings, please add the following
includeandexcludeproperties totsconfig.json:{ "extends": "astro/tsconfigs/base", + "include": [".astro/types.d.ts", "**/*"], + "exclude": ["dist"] } -
#11715
d74617cThanks @Princesseuh! - Refactor the exported types from theastromodule. There should normally be no breaking changes, but if you relied on some previously deprecated types, these might now have been fully removed.In most cases, updating your code to move away from previously deprecated APIs in previous versions of Astro should be enough to fix any issues.
-
#12551
abf9a89Thanks @ematipico! - Refactors legacycontentanddatacollections to use the Content Layer APIglob()loader for better performance and to support backwards compatibility. Also introduces thelegacy.collectionsflag for projects that are unable to update to the new behavior immediately.⚠️ BREAKING CHANGE FOR LEGACY CONTENT COLLECTIONS ⚠️
By default, collections that use the old types (
contentordata) and do not define aloaderare now implemented under the hood using the Content Layer API's built-inglob()loader, with extra backward-compatibility handling.In order to achieve backwards compatibility with existing
contentcollections, the following have been implemented:- a
globloader collection is defined, with patterns that match the previous handling (matchessrc/content/<collection name>/**/*.mdand other content extensions depending on installed integrations, with underscore-prefixed files and folders ignored) - When used in the runtime, the entries have an ID based on the filename in the same format as legacy collections
- A
slugfield is added with the same format as before - A
render()method is added to the entry, so they can be called usingentry.render() getEntryBySlugis supported
In order to achieve backwards compatibility with existing
datacollections, the following have been implemented:- a
globloader collection is defined, with patterns that match the previous handling (matchessrc/content/<collection name>/**/*{.json,.yaml}and other data extensions, with underscore-prefixed files and folders ignored) - Entries have an ID that is not slugified
getDataEntryByIdis supported
While this backwards compatibility implementation is able to emulate most of the features of legacy collections, there are some differences and limitations that may cause breaking changes to existing collections:
- In previous versions of Astro, collections would be generated for all folders in
src/content/, even if they were not defined insrc/content/config.ts. This behavior is now deprecated, and collections should always be defined insrc/content/config.ts. For existing collections, these can just be empty declarations (e.g.const blog = defineCollection({})) and Astro will implicitly define your legacy collection for you in a way that is compatible with the new loading behavior. - The special
layoutfield is not supported in Markdown collection entries. This property is intended only for standalone page files located insrc/pages/and not likely to be in your collection entries. However, if you were using this property, you must now create dynamic routes that include your page styling. - Sort order of generated collections is non-deterministic and platform-dependent. This means that if you are calling
getCollection(), the order in which entries are returned may be different than before. If you need a specific order, you should sort the collection entries yourself. image().refine()is not supported. If you need to validate the properties of an image you will need to do this at runtime in your page or component.- the
keyargument ofgetEntry(collection, key)is typed asstring, rather than having types for every entry.
A new legacy configuration flag
legacy.collectionsis added for users that want to keep their current legacy (content and data) collections behavior (available in Astro v2 - v4), or who are not yet ready to update their projects:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ legacy: { collections: true, }, });When set, no changes to your existing collections are necessary, and the restrictions on storing both new and old collections continue to exist: legacy collections (only) must continue to remain in
src/content/, while new collections using a loader from the Content Layer API are forbidden in that folder. - a
-
#11660
e90f559Thanks @bluwy! - Fixes attribute rendering for non-boolean HTML attributes with boolean values to match proper attribute handling in browsers.Previously, non-boolean attributes may not have included their values when rendered to HTML. In Astro v5.0, the values are now explicitly rendered as
="true"or="false"In the following
.astroexamples, onlyallowfullscreenis a boolean attribute:<!-- src/pages/index.astro --><!-- `allowfullscreen` is a boolean attribute --> <p allowfullscreen={true}></p> <p allowfullscreen={false}></p> <!-- `inherit` is *not* a boolean attribute --> <p inherit={true}></p> <p inherit={false}></p> <!-- `data-*` attributes are not boolean attributes --> <p data-light={true}></p> <p data-light={false}></p>Astro v5.0 now preserves the full data attribute with its value when rendering the HTML of non-boolean attributes:
<p allowfullscreen></p> <p></p> <p inherit="true"></p> - <p inherit></p> + <p inherit="false"></p> - <p data-light></p> + <p data-light="true"></p> - <p></p> + <p data-light="false"></p>If you rely on attribute values, for example to locate elements or to conditionally render, update your code to match the new non-boolean attribute values:
- el.getAttribute('inherit') === '' + el.getAttribute('inherit') === 'false' - el.hasAttribute('data-light') + el.dataset.light === 'true' -
#11770
cfa6a47Thanks @Princesseuh! - Removed support for the Squoosh image service. As the underlying librarylibsquooshis no longer maintained, and the image service sees very little usage we have decided to remove it from Astro.Our recommendation is to use the base Sharp image service, which is more powerful, faster, and more actively maintained.
- import { squooshImageService } from "astro/config"; import { defineConfig } from "astro/config"; export default defineConfig({ - image: { - service: squooshImageService() - } });If you are using this service, and cannot migrate to the base Sharp image service, a third-party extraction of the previous service is available here: https://github.com/Princesseuh/astro-image-service-squoosh
-
#12231
90ae100Thanks @bluwy! - Updates the automaticcharset=utf-8behavior for Markdown pages, where instead of responding withcharset=utf-8in theContent-Typeheader, Astro will now automatically add the<meta charset="utf-8">tag instead.This behaviour only applies to Markdown pages (
.mdor similar Markdown files located withinsrc/pages/) that do not use Astro's speciallayoutfrontmatter property. It matches the rendering behaviour of other non-content pages, and retains the minimal boilerplate needed to write with non-ASCII characters when adding individual Markdown pages to your site.If your Markdown pages use the
layoutfrontmatter property, then HTML encoding will be handled by the designated layout component instead, and the<meta charset="utf-8">tag will not be added to your page by default.If you require
charset=utf-8to render your page correctly, make sure that your layout components contain the<meta charset="utf-8">tag. You may need to add this if you have not already done so. -
#11714
8a53517Thanks @matthewp! - Remove support for functionPerRouteThis change removes support for the
functionPerRouteoption both in Astro and@astrojs/vercel.This option made it so that each route got built as separate entrypoints so that they could be loaded as separate functions. The hope was that by doing this it would decrease the size of each function. However in practice routes use most of the same code, and increases in function size limitations made the potential upsides less important.
Additionally there are downsides to functionPerRoute, such as hitting limits on the number of functions per project. The feature also never worked with some Astro features like i18n domains and request rewriting.
Given this, the feature has been removed from Astro.
-
#11864
ee38b3aThanks @ematipico! - ### [changed]:RouteData.distURLis now an array In Astro v4.x,RouteData.distURLwasundefinedor aURLAstro v5.0,
RouteData.distURLisundefinedor an array ofURL. This was a bug, because a route can generate multiple files on disk, especially when using dynamic routes such as[slug]or[...slug].What should I do?
Update your code to handle
RouteData.distURLas an array.if (route.distURL) { - if (route.distURL.endsWith('index.html')) { - // do something - } + for (const url of route.distURL) { + if (url.endsWith('index.html')) { + // do something + } + } } -
#11253
4e5cc5aThanks @kevinzunigacuellar! - Changes the data returned forpage.url.current,page.url.next,page.url.prev,page.url.firstandpage.url.lastto include the value set forbasein your Astro config.Previously, you had to manually prepend your configured value for
baseto the URL path. Now, Astro automatically includes yourbasevalue innextandprevURLs.If you are using the
paginate()function for "previous" and "next" URLs, remove any existingbasevalue as it is now added for you:--- export async function getStaticPaths({ paginate }) { const astronautPages = [{ astronaut: 'Neil Armstrong', }, { astronaut: 'Buzz Aldrin', }, { astronaut: 'Sally Ride', }, { astronaut: 'John Glenn', }]; return paginate(astronautPages, { pageSize: 1 }); } const { page } = Astro.props; // `base: /'docs'` configured in `astro.config.mjs` - const prev = "/docs" + page.url.prev; + const prev = page.url.prev; --- <a id="prev" href={prev}>Back</a> -
#12079
7febf1fThanks @ematipico! -paramspassed ingetStaticPathsare no longer automatically decoded.[changed]:
paramsaren't decoded anymore.In Astro v4.x,
paramsin were automatically decoded usingdecodeURIComponent.Astro v5.0 doesn't automatically decode
paramsingetStaticPathsanymore, so you'll need to manually decode them yourself if neededWhat should I do?
If you were relying on the automatic decode, you'll need to manually decode it using
decodeURI.Note that the use of
decodeURIComponent) is discouraged forgetStaticPathsbecause it decodes more characters than it should, for example/,?,#and more.--- export function getStaticPaths() { return [ + { params: { id: decodeURI("%5Bpage%5D") } }, - { params: { id: "%5Bpage%5D" } }, ] } const { id } = Astro.params; ---
Minor Changes
-
#11941
b6a5f39Thanks @Princesseuh! - Adapters can now specify the build output type they're intended for using theadapterFeatures.buildOutputproperty. This property can be used to always generate a server output, even if the project doesn't have any server-rendered pages.{ 'astro:config:done': ({ setAdapter, config }) => { setAdapter({ name: 'my-adapter', adapterFeatures: { buildOutput: 'server', }, }); }, }If your adapter specifies
buildOutput: 'static', and the user's project contains server-rendered pages, Astro will warn in development and error at build time. Note that a hybrid output, containing both static and server-rendered pages, is considered to be aserveroutput, as a server is required to serve the server-rendered pages. -
#12067
c48916cThanks @stramel! - Adds experimental support for built-in SVG components.This feature allows you to import SVG files directly into your Astro project as components. By default, Astro will inline the SVG content into your HTML output.
To enable this feature, set
experimental.svgtotruein your Astro config:{ experimental: { svg: true, }, }To use this feature, import an SVG file in your Astro project, passing any common SVG attributes to the imported component. Astro also provides a
sizeattribute to set equalheightandwidthproperties:--- import Logo from './path/to/svg/file.svg'; --- <Logo size={24} />For a complete overview, and to give feedback on this experimental API, see the Feature RFC.
-
#12226
51d13e2Thanks @ematipico! - The following renderer fields and integration fields now acceptURLas a type:Renderers:
AstroRenderer.clientEntrpointAstroRenderer.serverEntrypoint
Integrations:
InjectedRoute.entrypointAstroIntegrationMiddleware.entrypointDevToolbarAppEntry.entrypoint
-
#12323
c280655Thanks @bluwy! - Updates to Vite 6.0.0-beta.6 -
#12243
eb41d13Thanks @florian-lefebvre! - ImprovesdefineConfigtype safety. TypeScript will now error if a group of related configuration options do not have consistent types. For example, you will now see an error if your language set fori18n.defaultLocaleis not one of the supported locales specified ini18n.locales. -
#12329
8309c61Thanks @florian-lefebvre! - Adds a newastro:routes:resolvedhook to the Integration API. Also update theastro:build:donehook by deprecatingroutesand adding a newassetsmap.When building an integration, you can now get access to routes inside the
astro:routes:resolvedhook:const integration = () => { return { name: 'my-integration', hooks: { 'astro:routes:resolved': ({ routes }) => { console.log(routes); }, }, }; };This hook runs before
astro:config:done, and whenever a route changes in development.The
routesarray fromastro:build:doneis now deprecated, and exposed properties are now available onastro:routes:resolved, except fordistURL. For this, you can use the newly exposedassetsmap:const integration = () => { + let routes return { name: 'my-integration', hooks: { + 'astro:routes:resolved': (params) => { + routes = params.routes + }, 'astro:build:done': ({ - routes + assets }) => { + for (const route of routes) { + const distURL = assets.get(route.pattern) + if (distURL) { + Object.assign(route, { distURL }) + } + } console.log(routes) } } } } -
#11911
c3dce83Thanks @ascorbic! - The Content Layer API introduced behind a flag in 4.14.0 is now stable and ready for use in Astro v5.0.The new Content Layer API builds upon content collections, taking them beyond local files in
src/content/and allowing you to fetch content from anywhere, including remote APIs. These new collections work alongside your existing content collections, and you can migrate them to the new API at your own pace. There are significant improvements to performance with large collections of local files. For more details, see the Content Layer RFC.If you previously used this feature, you can now remove the
experimental.contentLayerflag from your Astro config:// astro.config.mjs import { defineConfig } from 'astro' export default defineConfig({ - experimental: { - contentLayer: true - } })Loading your content
The core of the new Content Layer API is the loader, a function that fetches content from a source and caches it in a local data store. Astro 4.14 ships with built-in
glob()andfile()loaders to handle your local Markdown, MDX, Markdoc, and JSON files:// src/content/config.ts import { defineCollection, z } from 'astro:content'; import { glob } from 'astro/loaders'; const blog = defineCollection({ // The ID is a slug generated from the path of the file relative to `base` loader: glob({ pattern: '**/*.md', base: './src/data/blog' }), schema: z.object({ title: z.string(), description: z.string(), publishDate: z.coerce.date(), }), }); export const collections = { blog };You can then query using the existing content collections functions, and use a simplified
render()function to display your content:--- import { getEntry, render } from 'astro:content'; const post = await getEntry('blog', Astro.params.slug); const { Content } = await render(entry); --- <Content />Creating a loader
You're not restricted to the built-in loaders – we hope you'll try building your own. You can fetch content from anywhere and return an array of entries:
// src/content/config.ts const countries = defineCollection({ loader: async () => { const response = await fetch('https://restcountries.com/v3.1/all'); const data = await response.json(); // Must return an array of entries with an id property, // or an object with IDs as keys and entries as values return data.map((country) => ({ id: country.cca3, ...country, })); }, // optionally add a schema to validate the data and make it type-safe for users // schema: z.object... }); export const collections = { countries };For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading, and gives full access to the data store. It also allows a loader to define its own schema, including generating it dynamically based on the source API. See the the Content Layer API RFC for more details.
Sharing your loaders
Loaders are better when they're shared. You can create a package that exports a loader and publish it to npm, and then anyone can use it on their site. We're excited to see what the community comes up with! To get started, take a look at some examples. Here's how to load content using an RSS/Atom feed loader:
// src/content/config.ts import { defineCollection } from 'astro:content'; import { feedLoader } from '@ascorbic/feed-loader'; const podcasts = defineCollection({ loader: feedLoader({ url: 'https://feeds.99percentinvisible.org/99percentinvisible', }), }); export const collections = { podcasts };To learn more, see the Content Layer RFC.
-
#11980
a604a0cThanks @matthewp! - ViewTransitions component renamed to ClientRouterThe
<ViewTransitions />component has been renamed to<ClientRouter />. There are no other changes than the name. The old name will continue to work in Astro 5.x, but will be removed in 6.0.This change was done to clarify the role of the component within Astro's View Transitions support. Astro supports View Transitions APIs in a few different ways, and renaming the component makes it more clear that the features you get from the ClientRouter component are slightly different from what you get using the native CSS-based MPA router.
We still intend to maintain the ClientRouter as before, and it's still important for use-cases that the native support doesn't cover, such as persisting state between pages.
-
#11875
a8a3d2cThanks @florian-lefebvre! - Adds a new propertyisPrerenderedto the globalsAstroandAPIContext. This boolean value represents whether or not the current page is prerendered:--- // src/pages/index.astro export const prerender = true; ---// src/middleware.js export const onRequest = (ctx, next) => { console.log(ctx.isPrerendered); // it will log true return next(); }; -
#12047
21b5e80Thanks @rgodha24! - Adds a new optionalparserproperty to the built-infile()loader for content collections to support additional file types such astomlandcsv.The
file()loader now accepts a second argument that defines aparserfunction. This allows you to specify a custom parser (e.g.toml.parseorcsv-parse) to create a collection from a file's contents. Thefile()loader will automatically detect and parse JSON and YAML files (based on their file extension) with no need for aparser.This works with any type of custom file formats including
csvandtoml. The following example defines a content collectiondogsusing a.tomlfile.[[dogs]] id = "..." age = "..." [[dogs]] id = "..." age = "..."After importing TOML's parser, you can load the
dogscollection into your project by passing both a file path andparserto thefile()loader.import { defineCollection } from "astro:content" import { file } from "astro/loaders" import { parse as parseToml } from "toml" const dogs = defineCollection({ loader: file("src/data/dogs.toml", { parser: (text) => parseToml(text).dogs }), schema: /* ... */ }) // it also works with CSVs! import { parse as parseCsv } from "csv-parse/sync"; const cats = defineCollection({ loader: file("src/data/cats.csv", { parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })}) });The
parserargument also allows you to load a single collection from a nested JSON document. For example, this JSON file contains multiple collections:{ "dogs": [{}], "cats": [{}] }You can separate these collections by passing a custom
parserto thefile()loader like so:const dogs = defineCollection({ loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).dogs }), }); const cats = defineCollection({ loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).cats }), });And it continues to work with maps of
idtodatabubbles: breed: 'Goldfish' age: 2 finn: breed: 'Betta' age: 1const fish = defineCollection({ loader: file('src/data/fish.yaml'), schema: z.object({ breed: z.string(), age: z.number() }), }); -
#11698
05139efThanks @ematipico! - Adds a new property to the globalsAstroandAPIContextcalledroutePattern. TheroutePatternrepresents the current route (component) that is being rendered by Astro. It's usually a path pattern will look like this:blog/[slug]:--- // src/pages/blog/[slug].astro const route = Astro.routePattern; console.log(route); // it will log "blog/[slug]" ---// src/pages/index.js export const GET = (ctx) => { console.log(ctx.routePattern); // it will log src/pages/index.js return new Response.json({ loreum: 'ipsum' }); }; -
#11941
b6a5f39Thanks @Princesseuh! - Adds a newbuildOutputproperty to theastro:config:donehook returning the build output type.This can be used to know if the user's project will be built as a static site (HTML files), or a server-rendered site (whose exact output depends on the adapter).
-
#12377
af867f3Thanks @ascorbic! - Adds experimental support for automatic responsive imagesThis feature is experimental and may change in future versions. To enable it, set
experimental.responsiveImagestotruein yourastro.config.mjsfile.{ experimental: { responsiveImages: true, }, }When this flag is enabled, you can pass a
layoutprop to any<Image />or<Picture />component to create a responsive image. When a layout is set, images have automatically generatedsrcsetandsizesattributes based on the image's dimensions and the layout type. Images withresponsiveandfull-widthlayouts will have styles applied to ensure they resize according to their container.--- import { Image, Picture } from 'astro:assets'; import myImage from '../assets/my_image.png'; --- <Image src={myImage} alt="A description of my image." layout="responsive" width={800} height={600} /> <Picture src={myImage} alt="A description of my image." layout="full-width" formats={['avif', 'webp', 'jpeg']} />This
<Image />component will generate the following HTML output:<img src="/_astro/my_image.hash3.webp" srcset=" /_astro/my_image.hash1.webp 640w, /_astro/my_image.hash2.webp 750w, /_astro/my_image.hash3.webp 800w, /_astro/my_image.hash4.webp 828w, /_astro/my_image.hash5.webp 1080w, /_astro/my_image.hash6.webp 1280w, /_astro/my_image.hash7.webp 1600w " alt="A description of my image" sizes="(min-width: 800px) 800px, 100vw" loading="lazy" decoding="async" fetchpriority="auto" width="800" height="600" style="--w: 800; --h: 600; --fit: cover; --pos: center;" data-astro-image="responsive" />Responsive image properties
These are additional properties available to the
<Image />and<Picture />components when responsive images are enabled:layout: The layout type for the image. Can beresponsive,fixed,full-widthornone. Defaults to value ofimage.experimentalLayout.fit: Defines how the image should be cropped if the aspect ratio is changed. Values match those of CSSobject-fit. Defaults tocover, or the value ofimage.experimentalObjectFitif set.position: Defines the position of the image crop if the aspect ratio is changed. Values match those of CSSobject-position. Defaults tocenter, or the value ofimage.experimentalObjectPositionif set.priority: If set, eagerly loads the image. Otherwise images will be lazy-loaded. Use this for your largest above-the-fold image. Defaults tofalse.
Default responsive image settings
You can enable responsive images for all
<Image />and<Picture />components by settingimage.experimentalLayoutwith a default value. This can be overridden by thelayoutprop on each component.Example:
{ image: { // Used for all `<Image />` and `<Picture />` components unless overridden experimentalLayout: 'responsive', }, experimental: { responsiveImages: true, }, }--- import { Image } from 'astro:assets'; import myImage from '../assets/my_image.png'; --- <Image src={myImage} alt="This will use responsive layout" width={800} height={600} /> <Image src={myImage} alt="This will use full-width layout" layout="full-width" /> <Image src={myImage} alt="This will disable responsive images" layout="none" />For a complete overview, and to give feedback on this experimental API, see the Responsive Images RFC.
-
#12150
93351bcThanks @bluwy! - Adds support for passing values other than"production"or"development"to the--modeflag (e.g."staging","testing", or any custom value) to change the value ofimport.meta.env.MODEor the loaded.envfile. This allows you take advantage of Vite's mode feature.Also adds a new
--devOutputflag forastro buildthat will output a development-based build.Note that changing the
modedoes not change the kind of code transform handled by Vite and Astro:- In
astro dev, Astro will transform code with debug information. - In
astro build, Astro will transform code with the most optimized output and removes debug information. - In
astro build --devOutput(new flag), Astro will transform code with debug information like inastro dev.
This enables various usecases like:
# Run the dev server connected to a "staging" API astro dev --mode staging # Build a site that connects to a "staging" API astro build --mode staging # Build a site that connects to a "production" API with additional debug information astro build --devOutput # Build a site that connects to a "testing" API astro build --mode testingThe different modes can be used to load different
.envfiles, e.g..env.stagingor.env.production, which can be customized for each environment, for example with differentAPI_URLenvironment variable values. - In
-
#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. -
#11806
f7f2338Thanks @Princesseuh! - The value of the different properties onsupportedAstroFeaturesfor adapters can now be objects, with asupportandmessageproperties. The content of themessageproperty will be shown in the Astro CLI when the adapter is not compatible with the feature, allowing one to give a better informational message to the user.This is notably useful with the new
limitedvalue, to explain to the user why support is limited. -
#12071
61d248eThanks @Princesseuh! -astro addno longer automatically setsoutput: 'server'. Since the default value of output now allows for server-rendered pages, it no longer makes sense to default to full server builds when you add an adapter -
#11955
d813262Thanks @matthewp! - Server Islands introduced behind an experimental flag in v4.12.0 is no longer experimental and is available for general use.Server islands are Astro's solution for highly cacheable pages of mixed static and dynamic content. They allow you to specify components that should run on the server, allowing the rest of the page to be more aggressively cached, or even generated statically.
Turn any
.astrocomponent into a server island by adding theserver:deferdirective and optionally, fallback placeholder content. It will be rendered dynamically at runtime outside the context of the rest of the page, allowing you to add longer cache headers for the pages, or even prerender them.--- import Avatar from '../components/Avatar.astro'; import GenericUser from '../components/GenericUser.astro'; --- <header> <h1>Page Title</h1> <div class="header-right"> <Avatar server:defer> <GenericUser slot="fallback" /> </Avatar> </div> </header>If you were previously using this feature, please remove the experimental flag from your Astro config:
import { defineConfig } from 'astro/config'; export default defineConfig({ experimental { - serverIslands: true, }, });If you have been waiting for stabilization before using server islands, you can now do so.
Please see the server island documentation for more about this feature.
-
#12373
d10f918Thanks @bholmesdev! - Changes the default behavior for Astro Action form requests to a standard POST submission.In Astro 4.x, actions called from an HTML form would trigger a redirect with the result forwarded using cookies. This caused issues for large form errors and return values that exceeded the 4 KB limit of cookie-based storage.
Astro 5.0 now renders the result of an action as a POST result without any forwarding. This will introduce a "confirm form resubmission?" dialog when a user attempts to refresh the page, though it no longer imposes a 4 KB limit on action return value.
Customize form submission behavior
If you prefer to address the "confirm form resubmission?" dialog on refresh, or to preserve action results across sessions, you can now customize action result handling from middleware.
We recommend using a session storage provider as described in our Netlify Blob example. However, if you prefer the cookie forwarding behavior from 4.X and accept the 4 KB size limit, you can implement the pattern as shown in this sample snippet:
// src/middleware.ts import { defineMiddleware } from 'astro:middleware'; import { getActionContext } from 'astro:actions'; export const onRequest = defineMiddleware(async (context, next) => { // Skip requests for prerendered pages if (context.isPrerendered) return next(); const { action, setActionResult, serializeActionResult } = getActionContext(context); // If an action result was forwarded as a cookie, set the result // to be accessible from `Astro.getActionResult()` const payload = context.cookies.get('ACTION_PAYLOAD'); if (payload) { const { actionName, actionResult } = payload.json(); setActionResult(actionName, actionResult); context.cookies.delete('ACTION_PAYLOAD'); return next(); } // If an action was called from an HTML form action, // call the action handler and redirect with the result as a cookie. if (action?.calledFrom === 'form') { const actionResult = await action.handler(); context.cookies.set('ACTION_PAYLOAD', { actionName: action.name, actionResult: serializeActionResult(actionResult), }); if (actionResult.error) { // Redirect back to the previous page on error const referer = context.request.headers.get('Referer'); if (!referer) { throw new Error('Internal: Referer unexpectedly missing from Action POST request.'); } return context.redirect(referer); } // Redirect to the destination page on success return context.redirect(context.originPathname); } return next(); }); -
#12475
3f02d5fThanks @ascorbic! - Changes the default content config location fromsrc/content/config.*tosrc/content.config.*.The previous location is still supported, and is required if the
legacy.collectionsflag is enabled. -
#11963
0a1036eThanks @florian-lefebvre! - Adds a newcreateCodegenDir()function to theastro:config:setuphook in the Integrations APIIn 4.14, we introduced the
injectTypesutility on theastro:config:donehook. It can create.d.tsfiles and make their types available to user's projects automatically. Under the hood, it creates a file in<root>/.astro/integrations/<normalized_integration_name>.While the
.astrodirectory has always been the preferred place to write code generated files, it has also been prone to mistakes. For example, you can write a.astro/types.d.tsfile, breaking Astro types. Or you can create a file that overrides a file created by another integration.In this release,
<root>/.astro/integrations/<normalized_integration_name>can now be retrieved in theastro:config:setuphook by callingcreateCodegenDir(). It allows you to have a dedicated folder, avoiding conflicts with another integration or Astro itself. This directory is created by calling this function so it's safe to write files to it directly:import { writeFileSync } from 'node:fs'; const integration = { name: 'my-integration', hooks: { 'astro:config:setup': ({ createCodegenDir }) => { const codegenDir = createCodegenDir(); writeFileSync(new URL('cache.json', codegenDir), '{}', 'utf-8'); }, }, }; -
#12379
94f4fe8Thanks @Princesseuh! - Adds a new components exported fromastro/components: Welcome, to be used by the new Basics template -
#11806
f7f2338Thanks @Princesseuh! - Adds a newlimitedvalue for the different properties ofsupportedAstroFeaturesfor adapters, which indicates that the adapter is compatible with the feature, but with some limitations. This is useful for adapters that support a feature, but not in all cases or with all options. -
#11925
74722cbThanks @florian-lefebvre! - Updatesastro/configimport to referenceastro/clienttypesWhen importing
astro/config, types fromastro/clientwill be made automatically available to your project. If your projecttsconfig.jsonchanges how references behave, you'll still have access to these types after runningastro sync. -
#12081
8679954Thanks @florian-lefebvre! - Removes the experimentalcontentCollectionsCacheintroduced in3.5.0.Astro Content Layer API independently solves some of the caching and performance issues with legacy content collections that this strategy attempted to address. This feature has been replaced with continued work on improvements to the content layer. If you were using this experimental feature, you must now remove the flag from your Astro config as it no longer exists:
export default defineConfig({ experimental: { - contentCollectionsCache: true } })The
cacheManifestboolean argument is no longer passed to theastro:build:doneintegration hook:const integration = { name: "my-integration", hooks: { "astro:build:done": ({ - cacheManifest, logger }) => {} } }
Patch Changes
-
#12565
97f413fThanks @ascorbic! - Fixes a bug where content types were not generated when first running astro dev unless src/content exists -
#11987
bf90a53Thanks @florian-lefebvre! -render()signature now takesrenderOptionsas 2nd argumentThe signature for
app.render()has changed, and the second argument is now an options object calledrenderOptionswith more options for customizing rendering.The
renderOptionsare:addCookieHeader: Determines whether Astro will set theSet-Cookieheader, otherwise the adapter is expected to do so itself.clientAddress: The client IP address used to setAstro.clientAddress.locals: An object of locals that's set toAstro.locals.routeData: An object specifying the route to use.
-
#12522
33b0e30Thanks @ascorbic! - Fixes a bug where content config was ignored if it was outside of content dir and has a parent dir with an underscore -
#12424
4364bffThanks @ematipico! - Fixes an issue where an incorrect usage of Astro actions was lost when porting the fix from v4 to v5 -
#12438
c8f877cThanks @ascorbic! - Fixes a bug where legacy content types were generated for content layer collections if they were in the content directory -
#12035
325a57cThanks @ascorbic! - Correctly parse values returned from inline loader -
#11960
4410130Thanks @ascorbic! - Fixes an issue where the refresh context data was not passed correctly to content layer loaders -
#11878
334948cThanks @ascorbic! - Adds a new functionrefreshContentto theastro:server:setuphook that allows integrations to refresh the content layer. This can be used, for example, to register a webhook endpoint during dev, or to open a socket to a CMS to listen for changes.By default,
refreshContentwill refresh all collections. You can optionally pass aloadersproperty, which is an array of loader names. If provided, only collections that use those loaders will be refreshed. For example, A CMS integration could use this property to only refresh its own collections.You can also pass a
contextobject to the loaders. This can be used to pass arbitrary data, such as the webhook body, or an event from the websocket.{ name: 'my-integration', hooks: { 'astro:server:setup': async ({ server, refreshContent }) => { server.middlewares.use('/_refresh', async (req, res) => { if(req.method !== 'POST') { res.statusCode = 405 res.end('Method Not Allowed'); return } let body = ''; req.on('data', chunk => { body += chunk.toString(); }); req.on('end', async () => { try { const webhookBody = JSON.parse(body); await refreshContent({ context: { webhookBody }, loaders: ['my-loader'] }); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Content refreshed successfully' })); } catch (error) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Failed to refresh content: ' + error.message })); } }); }); } } } -
#11991
d7a396cThanks @matthewp! - Update error link to on-demand rendering guide -
#12127
55e9cd8Thanks @ascorbic! - Prevents Vite emitting an error when restarting itself -
#12516
cb9322cThanks @stramel! - Handle multiple root nodes on SVG files -
#11974
60211deThanks @ascorbic! - Exports theRenderResulttype -
#12578
07b9ca8Thanks @WesSouza! - Explicitly import index.ts to fix types when moduleResolution is NodeNext -
#11791
9393243Thanks @bluwy! - Updates Astro's default<script>rendering strategy and removes theexperimental.directRenderScriptoption as this is now the default behavior: scripts are always rendered directly. This new strategy prevents 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>, multiple scripts on a page are no longer bundled together, and the<script>tag may interfere with the CSS styling.As this is a potentially breaking change to your script behavior, please review your
<script>tags and ensure that they behave as expected. -
#12011
cfdaab2Thanks @ArmandPhilippot! - Fixes a type and an example in documenting thesecurity.checkOriginproperty of Astro config. -
#12168
1cd3085Thanks @ascorbic! - Allows "slug" as a field in content layer data -
#12302
7196c24Thanks @ematipico! - Fixes an issue where the origin check middleware run for prendered pages -
#12341
c1786d6Thanks @ematipico! - Fixes and issue whereAstro.currentLocalealways returned the default locale when consumed inside a server island. -
#11732
4cd6c43Thanks @matthewp! - Use GET requests with preloading for Server IslandsServer Island requests include the props used to render the island as well as any slots passed in (excluding the fallback slot). Since browsers have a max 4mb URL length we default to using a POST request to avoid overflowing this length.
However in reality most usage of Server Islands are fairly isolated and won't exceed this limit, so a GET request is possible by passing this same information via search parameters.
Using GET means we can also include a
<link rel="preload">tag to speed up the request.This change implements this, with safe fallback to POST.
-
#11952
50a0146Thanks @ascorbic! - Adds support for array patterns in the built-inglob()content collections loaderThe glob loader can now accept an array of multiple patterns as well as string patterns. This allows you to more easily combine multiple patterns into a single collection, and also means you can use negative matches to exclude files from the collection.
const probes = defineCollection({ // Load all markdown files in the space-probes directory, except for those that start with "voyager-" loader: glob({ pattern: ['*.md', '!voyager-*'], base: 'src/data/space-probes' }), schema: z.object({ name: z.string(), type: z.enum(['Space Probe', 'Mars Rover', 'Comet Lander']), launch_date: z.date(), status: z.enum(['Active', 'Inactive', 'Decommissioned']), destination: z.string(), operator: z.string(), notable_discoveries: z.array(z.string()), }), }); -
#12022
ddc3a08Thanks @Princesseuh! - Properly handle including trailing slash on the image endpoint route based on the trailingSlash config -
#12169
15fa9baThanks @ematipico! - Fixes a bug where configured redirects were incorrectly constructed when reading the file system.This caused an issue where configuring a redirect in
astro.config.mjslike{ /old: /new }, failed to trigger the correct redirect in the dev server. -
#11914
b5d827bThanks @ascorbic! - Exports types for allLoaderContextproperties fromastro/loadersto make it easier to use them in custom loaders. TheScopedDataStoreinterface (which was previously internal) is renamed toDataStore, to reflect the fact that it's the only public API for the data store. -
#12270
25192a0Thanks @ematipico! - Fixes a bug where the params weren't correctly computed when rendering URLs with non-English characters -
#11927
5b4e3abThanks @florian-lefebvre! - Updates theenvconfiguration reference docs to include a full API reference forenvField. -
#12591
b731b3dThanks @ascorbic! - Fixes a bug where a catchall route would match an image endpoint request -
#12073
acf264dThanks @bluwy! - Replacesorawithyocto-spinner -
#12339
bdb75a8Thanks @ematipico! - Adds an error whenAstro.rewrite()is used to rewrite an on-demand route with a static route when using the"server"output.This is a forbidden rewrite because Astro can't retrieve the emitted static route at runtime. This route is served by the hosting platform, and not Astro itself.
-
#12511
d023682Thanks @stramel! - Fix SVG Component sprite references -
#12486
dc3d842Thanks @matthewp! - Call server island early so it can set headers -
#12016
837ee3aThanks @matthewp! - Fixes actions with large amount of validation errors -
#11943
fa4671cThanks @sarah11918! - Updates error messages that assume content collections are located insrc/content/with more generic language -
#12030
10a756aThanks @ascorbic! - Resolves image paths in content layer with initial slash as project-relativeWhen using the
image()schema helper, previously paths with an initial slash were treated as public URLs. This was to match the behavior of markdown images. However this is a change from before, where paths with an initial slash were treated as project-relative. This change restores the previous behavior, so that paths with an initial slash are treated as project-relative. -
#12009
f10a3b7Thanks @matthewp! - Fixes use of Vitest with Astro 5 -
#12075
a19530eThanks @bluwy! - Parses frontmatter ourselves -
#12552
15f000cThanks @avanderbergh! - Fixed an issue where modifying theRequest.headersprototype during prerendering caused a build error. Removed conflicting value and writable properties from theheadersdescriptor to preventInvalid property descriptorerrors. -
#12070
9693ad4Thanks @ematipico! - Fixes an issue where the check origin middleware was incorrectly injected when the build output was"static" -
#12169
15fa9baThanks @ematipico! - Fixes a bug where the dev server was not providing a consistent user experience for configured redirects.With the fix, when you configure a redirect in
astro.config.mjslike this{ /old: "/new" }, the dev server return an HTML response that matches the one emitted by a static build. -
Updated dependencies [
3ab3b4e,5608338,827093e,560ef15,83a2a64,3ab3b4e,a19530e,1dc8f5e]:- @astrojs/markdown-remark@6.0.0
- @astrojs/telemetry@3.2.0
- @astrojs/internal-helpers@0.4.2
5.0.0-beta.12
Major Changes
Minor Changes
Patch Changes
- Updated dependencies [
827093e]:- @astrojs/telemetry@3.2.0-beta.0
- @astrojs/markdown-remark@6.0.0-beta.3
5.0.0-beta.11
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.
Patch Changes
-
#12522
33b0e30Thanks @ascorbic! - Fixes a bug where content config was ignored if it was outside of content dir and has a parent dir with an underscore -
#12516
cb9322cThanks @stramel! - Handle multiple root nodes on SVG files -
#12511
d023682Thanks @stramel! - Fix SVG Component sprite references -
#12498
b140a3fThanks @ematipico! - Fixes a regression where Astro was trying to accessRequest.headers
5.0.0-beta.10
Patch Changes
5.0.0-beta.9
Minor Changes
-
#12067
c48916cThanks @stramel! - Adds experimental support for built-in SVG components.This feature allows you to import SVG files directly into your Astro project as components. By default, Astro will inline the SVG content into your HTML output.
To enable this feature, set
experimental.svgtotruein your Astro config:{ experimental: { svg: true, }, }To use this feature, import an SVG file in your Astro project, passing any common SVG attributes to the imported component. Astro also provides a
sizeattribute to set equalheightandwidthproperties:--- import Logo from './path/to/svg/file.svg'; --- <Logo size={24} />For a complete overview, and to give feedback on this experimental API, see the Feature RFC.
-
#12329
8309c61Thanks @florian-lefebvre! - Adds a newastro:routes:resolvedhook to the Integration API. Also update theastro:build:donehook by deprecatingroutesand adding a newassetsmap.When building an integration, you can now get access to routes inside the
astro:routes:resolvedhook:const integration = () => { return { name: 'my-integration', hooks: { 'astro:routes:resolved': ({ routes }) => { console.log(routes); }, }, }; };This hook runs before
astro:config:done, and whenever a route changes in development.The
routesarray fromastro:build:doneis now deprecated, and exposed properties are now available onastro:routes:resolved, except fordistURL. For this, you can use the newly exposedassetsmap:const integration = () => { + let routes return { name: 'my-integration', hooks: { + 'astro:routes:resolved': (params) => { + routes = params.routes + }, 'astro:build:done': ({ - routes + assets }) => { + for (const route of routes) { + const distURL = assets.get(route.pattern) + if (distURL) { + Object.assign(route, { distURL }) + } + } console.log(routes) } } } } -
#12377
af867f3Thanks @ascorbic! - Adds experimental support for automatic responsive imagesThis feature is experimental and may change in future versions. To enable it, set
experimental.responsiveImagestotruein yourastro.config.mjsfile.{ experimental: { responsiveImages: true, }, }When this flag is enabled, you can pass a
layoutprop to any<Image />or<Picture />component to create a responsive image. When a layout is set, images have automatically generatedsrcsetandsizesattributes based on the image's dimensions and the layout type. Images withresponsiveandfull-widthlayouts will have styles applied to ensure they resize according to their container.--- import { Image, Picture } from 'astro:assets'; import myImage from '../assets/my_image.png'; --- <Image src={myImage} alt="A description of my image." layout="responsive" width={800} height={600} /> <Picture src={myImage} alt="A description of my image." layout="full-width" formats={['avif', 'webp', 'jpeg']} />This
<Image />component will generate the following HTML output:<img src="/_astro/my_image.hash3.webp" srcset=" /_astro/my_image.hash1.webp 640w, /_astro/my_image.hash2.webp 750w, /_astro/my_image.hash3.webp 800w, /_astro/my_image.hash4.webp 828w, /_astro/my_image.hash5.webp 1080w, /_astro/my_image.hash6.webp 1280w, /_astro/my_image.hash7.webp 1600w " alt="A description of my image" sizes="(min-width: 800px) 800px, 100vw" loading="lazy" decoding="async" fetchpriority="auto" width="800" height="600" style="--w: 800; --h: 600; --fit: cover; --pos: center;" data-astro-image="responsive" />Responsive image properties
These are additional properties available to the
<Image />and<Picture />components when responsive images are enabled:layout: The layout type for the image. Can beresponsive,fixed,full-widthornone. Defaults to value ofimage.experimentalLayout.fit: Defines how the image should be cropped if the aspect ratio is changed. Values match those of CSSobject-fit. Defaults tocover, or the value ofimage.experimentalObjectFitif set.position: Defines the position of the image crop if the aspect ratio is changed. Values match those of CSSobject-position. Defaults tocenter, or the value ofimage.experimentalObjectPositionif set.priority: If set, eagerly loads the image. Otherwise images will be lazy-loaded. Use this for your largest above-the-fold image. Defaults tofalse.
Default responsive image settings
You can enable responsive images for all
<Image />and<Picture />components by settingimage.experimentalLayoutwith a default value. This can be overridden by thelayoutprop on each component.Example:
{ image: { // Used for all `<Image />` and `<Picture />` components unless overridden experimentalLayout: 'responsive', }, experimental: { responsiveImages: true, }, }--- import { Image } from 'astro:assets'; import myImage from '../assets/my_image.png'; --- <Image src={myImage} alt="This will use responsive layout" width={800} height={600} /> <Image src={myImage} alt="This will use full-width layout" layout="full-width" /> <Image src={myImage} alt="This will disable responsive images" layout="none" />For a complete overview, and to give feedback on this experimental API, see the Responsive Images RFC.
-
#12475
3f02d5fThanks @ascorbic! - Changes the default content config location fromsrc/content/config.*tosrc/content.config.*.The previous location is still supported, and is required if the
legacy.collectionsflag is enabled.
Patch Changes
-
#12424
4364bffThanks @ematipico! - Fixes an issue where an incorrect usage of Astro actions was lost when porting the fix from v4 to v5 -
#12438
c8f877cThanks @ascorbic! - Fixes a bug where legacy content types were generated for content layer collections if they were in the content directory
5.0.0-beta.8
Minor Changes
-
#12373
d10f918Thanks @bholmesdev! - Changes the default behavior for Astro Action form requests to a standard POST submission.In Astro 4.x, actions called from an HTML form would trigger a redirect with the result forwarded using cookies. This caused issues for large form errors and return values that exceeded the 4 KB limit of cookie-based storage.
Astro 5.0 now renders the result of an action as a POST result without any forwarding. This will introduce a "confirm form resubmission?" dialog when a user attempts to refresh the page, though it no longer imposes a 4 KB limit on action return value.
Customize form submission behavior
If you prefer to address the "confirm form resubmission?" dialog on refresh, or to preserve action results across sessions, you can now customize action result handling from middleware.
We recommend using a session storage provider as described in our Netlify Blob example. However, if you prefer the cookie forwarding behavior from 4.X and accept the 4 KB size limit, you can implement the pattern as shown in this sample snippet:
// src/middleware.ts import { defineMiddleware } from 'astro:middleware'; import { getActionContext } from 'astro:actions'; export const onRequest = defineMiddleware(async (context, next) => { // Skip requests for prerendered pages if (context.isPrerendered) return next(); const { action, setActionResult, serializeActionResult } = getActionContext(context); // If an action result was forwarded as a cookie, set the result // to be accessible from `Astro.getActionResult()` const payload = context.cookies.get('ACTION_PAYLOAD'); if (payload) { const { actionName, actionResult } = payload.json(); setActionResult(actionName, actionResult); context.cookies.delete('ACTION_PAYLOAD'); return next(); } // If an action was called from an HTML form action, // call the action handler and redirect with the result as a cookie. if (action?.calledFrom === 'form') { const actionResult = await action.handler(); context.cookies.set('ACTION_PAYLOAD', { actionName: action.name, actionResult: serializeActionResult(actionResult), }); if (actionResult.error) { // Redirect back to the previous page on error const referer = context.request.headers.get('Referer'); if (!referer) { throw new Error('Internal: Referer unexpectedly missing from Action POST request.'); } return context.redirect(referer); } // Redirect to the destination page on success return context.redirect(context.originPathname); } return next(); });
Patch Changes
-
#12339
bdb75a8Thanks @ematipico! - Adds an error whenAstro.rewrite()is used to rewrite an on-demand route with a static route when using the"server"output.This is a forbidden rewrite because Astro can't retrieve the emitted static route at runtime. This route is served by the hosting platform, and not Astro itself.
5.0.0-beta.7
Minor Changes
-
#12323
c280655Thanks @bluwy! - Updates to Vite 6.0.0-beta.6 -
#12379
94f4fe8Thanks @Princesseuh! - Adds a new components exported fromastro/components: Welcome, to be used by the new Basics template
5.0.0-beta.6
Major Changes
-
#12268
4e9a3acThanks @ematipico! - The commandastro add vercelnow updates the configuration file differently, and adds@astrojs/vercelas module to import.This is a breaking change because it requires the version
8.*of@astrojs/vercel. -
#12231
90ae100Thanks @bluwy! - Updates the automaticcharset=utf-8behavior for Markdown pages, where instead of responding withcharset=utf-8in theContent-Typeheader, Astro will now automatically add the<meta charset="utf-8">tag instead.This behaviour only applies to Markdown pages (
.mdor similar Markdown files located withinsrc/pages/) that do not use Astro's speciallayoutfrontmatter property. It matches the rendering behaviour of other non-content pages, and retains the minimal boilerplate needed to write with non-ASCII characters when adding individual Markdown pages to your site.If your Markdown pages use the
layoutfrontmatter property, then HTML encoding will be handled by the designated layout component instead, and the<meta charset="utf-8">tag will not be added to your page by default.If you require
charset=utf-8to render your page correctly, make sure that your layout components contain the<meta charset="utf-8">tag. You may need to add this if you have not already done so.
Minor Changes
-
#12243
eb41d13Thanks @florian-lefebvre! - ImprovesdefineConfigtype safety. TypeScript will now error if a group of related configuration options do not have consistent types. For example, you will now see an error if your language set fori18n.defaultLocaleis not one of the supported locales specified ini18n.locales. -
#12150
93351bcThanks @bluwy! - Adds support for passing values other than"production"or"development"to the--modeflag (e.g."staging","testing", or any custom value) to change the value ofimport.meta.env.MODEor the loaded.envfile. This allows you take advantage of Vite's mode feature.Also adds a new
--devOutputflag forastro buildthat will output a development-based build.Note that changing the
modedoes not change the kind of code transform handled by Vite and Astro:- In
astro dev, Astro will transform code with debug information. - In
astro build, Astro will transform code with the most optimized output and removes debug information. - In
astro build --devOutput(new flag), Astro will transform code with debug information like inastro dev.
This enables various usecases like:
# Run the dev server connected to a "staging" API astro dev --mode staging # Build a site that connects to a "staging" API astro build --mode staging # Build a site that connects to a "production" API with additional debug information astro build --devOutput # Build a site that connects to a "testing" API astro build --mode testingThe different modes can be used to load different
.envfiles, e.g..env.stagingor.env.production, which can be customized for each environment, for example with differentAPI_URLenvironment variable values. - In
Patch Changes
-
#12302
7196c24Thanks @ematipico! - Fixes an issue where the origin check middleware run for prendered pages -
#12341
c1786d6Thanks @ematipico! - Fixes and issue whereAstro.currentLocalealways returned the default locale when consumed inside a server island. -
#12270
25192a0Thanks @ematipico! - Fixes a bug where the params weren't correctly computed when rendering URLs with non-English characters
5.0.0-beta.5
Minor Changes
-
#12226
51d13e2Thanks @ematipico! - The following renderer fields and integration fields now acceptURLas a type:Renderers:
AstroRenderer.clientEntrpointAstroRenderer.serverEntrypoint
Integrations:
InjectedRoute.entrypointAstroIntegrationMiddleware.entrypointDevToolbarAppEntry.entrypoint
Patch Changes
-
#12168
1cd3085Thanks @ascorbic! - Allows "slug" as a field in content layer data -
#12169
15fa9baThanks @ematipico! - Fixes a bug where configured redirects were incorrectly constructed when reading the file system.This caused an issue where configuring a redirect in
astro.config.mjslike{ /old: /new }, failed to trigger the correct redirect in the dev server. -
#12169
15fa9baThanks @ematipico! - Fixes a bug where the dev server was not providing a consistent user experience for configured redirects.With the fix, when you configure a redirect in
astro.config.mjslike this{ /old: "/new" }, the dev server return an HTML response that matches the one emitted by a static build.
5.0.0-beta.4
Major Changes
-
#11979
423dfc1Thanks @bluwy! - Bumpsvitedependency to v6.0.0-beta.2. The version is pinned and will be updated as new Vite versions publish to prevent unhandled breaking changes. For the full list of Vite-specific changes, see its changelog. -
#12100
abf9a89Thanks @astrobot-houston! - Refactors legacycontentanddatacollections to use the Content Layer APIglob()loader for better performance and to support backwards compatibility. Also introduces thelegacy.collectionsflag for projects that are unable to update to the new behavior immediately.⚠️ BREAKING CHANGE FOR LEGACY CONTENT COLLECTIONS ⚠️
By default, collections that use the old types (
contentordata) and do not define aloaderare now implemented under the hood using the Content Layer API's built-inglob()loader, with extra backward-compatibility handling.In order to achieve backwards compatibility with existing
contentcollections, the following have been implemented:- a
globloader collection is defined, with patterns that match the previous handling (matchessrc/content/<collection name>/**/*.mdand other content extensions depending on installed integrations, with underscore-prefixed files and folders ignored) - When used in the runtime, the entries have an ID based on the filename in the same format as legacy collections
- A
slugfield is added with the same format as before - A
render()method is added to the entry, so they can be called usingentry.render() getEntryBySlugis supported
In order to achieve backwards compatibility with existing
datacollections, the following have been implemented:- a
globloader collection is defined, with patterns that match the previous handling (matchessrc/content/<collection name>/**/*{.json,.yaml}and other data extensions, with underscore-prefixed files and folders ignored) - Entries have an ID that is not slugified
getDataEntryByIdis supported
While this backwards compatibility implementation is able to emulate most of the features of legacy collections, there are some differences and limitations that may cause breaking changes to existing collections:
- In previous versions of Astro, collections would be generated for all folders in
src/content/, even if they were not defined insrc/content/config.ts. This behavior is now deprecated, and collections should always be defined insrc/content/config.ts. For existing collections, these can just be empty declarations (e.g.const blog = defineCollection({})) and Astro will implicitly define your legacy collection for you in a way that is compatible with the new loading behavior. - The special
layoutfield is not supported in Markdown collection entries. This property is intended only for standalone page files located insrc/pages/and not likely to be in your collection entries. However, if you were using this property, you must now create dynamic routes that include your page styling. - Sort order of generated collections is non-deterministic and platform-dependent. This means that if you are calling
getCollection(), the order in which entries are returned may be different than before. If you need a specific order, you should sort the collection entries yourself. image().refine()is not supported. If you need to validate the properties of an image you will need to do this at runtime in your page or component.- the
keyargument ofgetEntry(collection, key)is typed asstring, rather than having types for every entry.
A new legacy configuration flag
legacy.collectionsis added for users that want to keep their current legacy (content and data) collections behavior (available in Astro v2 - v4), or who are not yet ready to update their projects:// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ legacy: { collections: true, }, });When set, no changes to your existing collections are necessary, and the restrictions on storing both new and old collections continue to exist: legacy collections (only) must continue to remain in
src/content/, while new collections using a loader from the Content Layer API are forbidden in that folder. - a
-
#12079
7febf1fThanks @ematipico! -paramspassed ingetStaticPathsare no longer automatically decoded.[changed]:
paramsaren't decoded anymore.In Astro v4.x,
paramsin were automatically decoded usingdecodeURIComponent.Astro v5.0 doesn't automatically decode
paramsingetStaticPathsanymore, so you'll need to manually decode them yourself if neededWhat should I do?
If you were relying on the automatic decode, you'll need to manually decode it using
decodeURI.Note that the use of
decodeURIComponent) is discouraged forgetStaticPathsbecause it decodes more characters than it should, for example/,?,#and more.--- export function getStaticPaths() { return [ + { params: { id: decodeURI("%5Bpage%5D") } }, - { params: { id: "%5Bpage%5D" } }, ] } const { id } = Astro.params; ---
Patch Changes
5.0.0-beta.3
Minor Changes
-
#12047
21b5e80Thanks @rgodha24! - Adds a new optionalparserproperty to the built-infile()loader for content collections to support additional file types such astomlandcsv.The
file()loader now accepts a second argument that defines aparserfunction. This allows you to specify a custom parser (e.g.toml.parseorcsv-parse) to create a collection from a file's contents. Thefile()loader will automatically detect and parse JSON and YAML files (based on their file extension) with no need for aparser.This works with any type of custom file formats including
csvandtoml. The following example defines a content collectiondogsusing a.tomlfile.[[dogs]] id = "..." age = "..." [[dogs]] id = "..." age = "..."After importing TOML's parser, you can load the
dogscollection into your project by passing both a file path andparserto thefile()loader.import { defineCollection } from "astro:content" import { file } from "astro/loaders" import { parse as parseToml } from "toml" const dogs = defineCollection({ loader: file("src/data/dogs.toml", { parser: (text) => parseToml(text).dogs }), schema: /* ... */ }) // it also works with CSVs! import { parse as parseCsv } from "csv-parse/sync"; const cats = defineCollection({ loader: file("src/data/cats.csv", { parser: (text) => parseCsv(text, { columns: true, skipEmptyLines: true })}) });The
parserargument also allows you to load a single collection from a nested JSON document. For example, this JSON file contains multiple collections:{ "dogs": [{}], "cats": [{}] }You can separate these collections by passing a custom
parserto thefile()loader like so:const dogs = defineCollection({ loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).dogs }), }); const cats = defineCollection({ loader: file('src/data/pets.json', { parser: (text) => JSON.parse(text).cats }), });And it continues to work with maps of
idtodatabubbles: breed: 'Goldfish' age: 2 finn: breed: 'Betta' age: 1const fish = defineCollection({ loader: file('src/data/fish.yaml'), schema: z.object({ breed: z.string(), age: z.number() }), }); -
#12071
61d248eThanks @Princesseuh! -astro addno longer automatically setsoutput: 'server'. Since the default value of output now allows for server-rendered pages, it no longer makes sense to default to full server builds when you add an adapter -
#11963
0a1036eThanks @florian-lefebvre! - Adds a newcreateCodegenDir()function to theastro:config:setuphook in the Integrations APIIn 4.14, we introduced the
injectTypesutility on theastro:config:donehook. It can create.d.tsfiles and make their types available to user's projects automatically. Under the hood, it creates a file in<root>/.astro/integrations/<normalized_integration_name>.While the
.astrodirectory has always been the preferred place to write code generated files, it has also been prone to mistakes. For example, you can write a.astro/types.d.tsfile, breaking Astro types. Or you can create a file that overrides a file created by another integration.In this release,
<root>/.astro/integrations/<normalized_integration_name>can now be retrieved in theastro:config:setuphook by callingcreateCodegenDir(). It allows you to have a dedicated folder, avoiding conflicts with another integration or Astro itself. This directory is created by calling this function so it's safe to write files to it directly:import { writeFileSync } from 'node:fs'; const integration = { name: 'my-integration', hooks: { 'astro:config:setup': ({ createCodegenDir }) => { const codegenDir = createCodegenDir(); writeFileSync(new URL('cache.json', codegenDir), '{}', 'utf-8'); }, }, }; -
#12081
8679954Thanks @florian-lefebvre! - Removes the experimentalcontentCollectionsCacheintroduced in3.5.0.Astro Content Layer API independently solves some of the caching and performance issues with legacy content collections that this strategy attempted to address. This feature has been replaced with continued work on improvements to the content layer. If you were using this experimental feature, you must now remove the flag from your Astro config as it no longer exists:
export default defineConfig({ experimental: { - contentCollectionsCache: true } })The
cacheManifestboolean argument is no longer passed to theastro:build:doneintegration hook:const integration = { name: "my-integration", hooks: { "astro:build:done": ({ - cacheManifest, logger }) => {} } }
Patch Changes
-
#12073
acf264dThanks @bluwy! - Replacesorawithyocto-spinner -
#12075
a19530eThanks @bluwy! - Parses frontmatter ourselves -
#12070
9693ad4Thanks @ematipico! - Fixes an issue where the check origin middleware was incorrectly injected when the build output was"static" -
Updated dependencies [
a19530e]:- @astrojs/markdown-remark@6.0.0-beta.2
5.0.0-beta.2
Patch Changes
-
#12035
325a57cThanks @ascorbic! - Correctly parse values returned from inline loader -
#12022
ddc3a08Thanks @Princesseuh! - Properly handle including trailing slash on the image endpoint route based on the trailingSlash config -
#12016
837ee3aThanks @matthewp! - Fixes actions with large amount of validation errors -
#12030
10a756aThanks @ascorbic! - Resolves image paths in content layer with initial slash as project-relativeWhen using the
image()schema helper, previously paths with an initial slash were treated as public URLs. This was to match the behavior of markdown images. However this is a change from before, where paths with an initial slash were treated as project-relative. This change restores the previous behavior, so that paths with an initial slash are treated as project-relative.
5.0.0-beta.1
Major Changes
-
#12008
5608338Thanks @Princesseuh! - Welcome to the Astro 5 beta! This release has no changes from the latest alpha of this package, but it does bring us one step closer to the final, stable release.Starting from this release, no breaking changes will be introduced unless absolutely necessary.
To learn how to upgrade, check out the Astro v5.0 upgrade guide in our beta docs site.
Patch Changes
- Updated dependencies [
5608338]:- @astrojs/markdown-remark@6.0.0-beta.1
5.0.0-alpha.9
Patch Changes
-
#12011
cfdaab2Thanks @ArmandPhilippot! - Fixes a type and an example in documenting thesecurity.checkOriginproperty of Astro config. -
#12009
f10a3b7Thanks @matthewp! - Fixes use of Vitest with Astro 5
5.0.0-alpha.8
Major Changes
-
#11982
d84e444Thanks @Princesseuh! - Adds a default exclude and include value to the tsconfig presets.{projectDir}/distis now excluded by default, and{projectDir}/.astro/types.d.tsand{projectDir}/**/*are included by default.Both of these options can be overridden by setting your own values to the corresponding settings in your
tsconfig.jsonfile. -
#11987
bf90a53Thanks @florian-lefebvre! - Thelocalsobject can no longer be overriddenMiddleware, API endpoints, and pages can no longer override the
localsobject in its entirety. You can still append values onto the object, but you can not replace the entire object and delete its existing values.If you were previously overwriting like so:
ctx.locals = { one: 1, two: 2, };This can be changed to an assignment on the existing object instead:
Object.assign(ctx.locals, { one: 1, two: 2, });
Minor Changes
-
#11980
a604a0cThanks @matthewp! - ViewTransitions component renamed to ClientRouterThe
<ViewTransitions />component has been renamed to<ClientRouter />. There are no other changes than the name. The old name will continue to work in Astro 5.x, but will be removed in 6.0.This change was done to clarify the role of the component within Astro's View Transitions support. Astro supports View Transitions APIs in a few different ways, and renaming the component makes it more clear that the features you get from the ClientRouter component are slightly different from what you get using the native CSS-based MPA router.
We still intend to maintain the ClientRouter as before, and it's still important for use-cases that the native support doesn't cover, such as persisting state between pages.
Patch Changes
-
#11987
bf90a53Thanks @florian-lefebvre! -render()signature now takesrenderOptionsas 2nd argumentThe signature for
app.render()has changed, and the second argument is now an options object calledrenderOptionswith more options for customizing rendering.The
renderOptionsare:addCookieHeader: Determines whether Astro will set theSet-Cookieheader, otherwise the adapter is expected to do so itself.clientAddress: The client IP address used to setAstro.clientAddress.locals: An object of locals that's set toAstro.locals.routeData: An object specifying the route to use.
-
#11991
d7a396cThanks @matthewp! - Update error link to on-demand rendering guide
5.0.0-alpha.7
Major Changes
-
#11864
ee38b3aThanks @ematipico! - ### [changed]:entryPointtype inside the hookastro:build:ssrIn Astro v4.x, theentryPointtype wasRouteData.Astro v5.0 the
entryPointtype isIntegrationRouteData, which contains a subset of theRouteDatatype. The fieldsisIndexandfallbackRouteswere removed.What should I do?
Update your adapter to change the type of
entryPointfromRouteDatatoIntegrationRouteData.-import type {RouteData} from 'astro'; +import type {IntegrationRouteData} from "astro" -function useRoute(route: RouteData) { +function useRoute(route: IntegrationRouteData) { } -
#11908
518433eThanks @Princesseuh! - Theimage.endpointconfig now allow customizing the route of the image endpoint in addition to the entrypoint. This can be useful in niche situations where the default route/_imageconflicts with an existing route or your local server setup.import { defineConfig } from 'astro/config'; defineConfig({ image: { endpoint: { route: '/image', entrypoint: './src/image_endpoint.ts', }, }, }); -
#11806
f7f2338Thanks @Princesseuh! - Removes theassetsproperty onsupportedAstroFeaturesfor adapters, as it did not reflect reality properly in many cases.Now, relating to assets, only a single
sharpImageServiceproperty is available, determining if the adapter is compatible with the built-in sharp image service. -
#11864
ee38b3aThanks @ematipico! - ### [changed]:routestype inside the hookastro:build:doneIn Astro v4.x, theroutestype wasRouteData.Astro v5.0 the
routestype isIntegrationRouteData, which contains a subset of theRouteDatatype. The fieldsisIndexandfallbackRouteswere removed.What should I do?
Update your adapter to change the type of
routesfromRouteDatatoIntegrationRouteData.-import type {RouteData} from 'astro'; +import type {IntegrationRouteData} from "astro" -function useRoute(route: RouteData) { +function useRoute(route: IntegrationRouteData) { } -
#11864
ee38b3aThanks @ematipico! - ### [changed]:RouteData.distURLis now an array In Astro v4.x,RouteData.distURLwasundefinedor aURLAstro v5.0,
RouteData.distURLisundefinedor an array ofURL. This was a bug, because a route can generate multiple files on disk, especially when using dynamic routes such as[slug]or[...slug].What should I do?
Update your code to handle
RouteData.distURLas an array.if (route.distURL) { - if (route.distURL.endsWith('index.html')) { - // do something - } + for (const url of route.distURL) { + if (url.endsWith('index.html')) { + // do something + } + } }
Minor Changes
-
#11806
f7f2338Thanks @Princesseuh! - The value of the different properties onsupportedAstroFeaturesfor adapters can now be objects, with asupportandmessageproperties. The content of themessageproperty will be shown in the Astro CLI when the adapter is not compatible with the feature, allowing one to give a better informational message to the user.This is notably useful with the new
limitedvalue, to explain to the user why support is limited. -
#11955
d813262Thanks @matthewp! - Server Islands introduced behind an experimental flag in v4.12.0 is no longer experimental and is available for general use.Server islands are Astro's solution for highly cacheable pages of mixed static and dynamic content. They allow you to specify components that should run on the server, allowing the rest of the page to be more aggressively cached, or even generated statically.
Turn any
.astrocomponent into a server island by adding theserver:deferdirective and optionally, fallback placeholder content. It will be rendered dynamically at runtime outside the context of the rest of the page, allowing you to add longer cache headers for the pages, or even prerender them.--- import Avatar from '../components/Avatar.astro'; import GenericUser from '../components/GenericUser.astro'; --- <header> <h1>Page Title</h1> <div class="header-right"> <Avatar server:defer> <GenericUser slot="fallback" /> </Avatar> </div> </header>If you were previously using this feature, please remove the experimental flag from your Astro config:
import { defineConfig } from 'astro/config'; export default defineConfig({ experimental { - serverIslands: true, }, });If you have been waiting for stabilization before using server islands, you can now do so.
Please see the server island documentation for more about this feature.
-
#11806
f7f2338Thanks @Princesseuh! - Adds a newlimitedvalue for the different properties ofsupportedAstroFeaturesfor adapters, which indicates that the adapter is compatible with the feature, but with some limitations. This is useful for adapters that support a feature, but not in all cases or with all options. -
#11925
74722cbThanks @florian-lefebvre! - Updatesastro/configimport to referenceastro/clienttypesWhen importing
astro/config, types fromastro/clientwill be made automatically available to your project. If your projecttsconfig.jsonchanges how references behave, you'll still have access to these types after runningastro sync.
Patch Changes
5.0.0-alpha.6
Major Changes
-
#11941
b6a5f39Thanks @Princesseuh! - Merges theoutput: 'hybrid'andoutput: 'static'configurations into one single configuration (now called'static') that works the same way as the previoushybridoption.It is no longer necessary to specify
output: 'hybrid'in your Astro config to use server-rendered pages. The newoutput: 'static'has this capability included. Astro will now automatically provide the ability to opt out of prerendering in your static site with no change to youroutputconfiguration required. Any page route or endpoint can includeexport const prerender = falseto be server-rendered, while the rest of your site is statically-generated.If your project used hybrid rendering, you must now remove the
output: 'hybrid'option from your Astro config as it no longer exists. However, no other changes to your project are required, and you should have no breaking changes. The previous'hybrid'behavior is now the default, under a new name'static'.If you were using the
output: 'static'(default) option, you can continue to use it as before. By default, all of your pages will continue to be prerendered and you will have a completely static site. You should have no breaking changes to your project.import { defineConfig } from "astro/config"; export default defineConfig({ - output: 'hybrid', });An adapter is still required to deploy an Astro project with any server-rendered pages. Failure to include an adapter will result in a warning in development and an error at build time.
Minor Changes
-
#11941
b6a5f39Thanks @Princesseuh! - Adapters can now specify the build output type they're intended for using theadapterFeatures.buildOutputproperty. This property can be used to always generate a server output, even if the project doesn't have any server-rendered pages.{ 'astro:config:done': ({ setAdapter, config }) => { setAdapter({ name: 'my-adapter', adapterFeatures: { buildOutput: 'server', }, }); }, }If your adapter specifies
buildOutput: 'static', and the user's project contains server-rendered pages, Astro will warn in development and error at build time. Note that a hybrid output, containing both static and server-rendered pages, is considered to be aserveroutput, as a server is required to serve the server-rendered pages. -
#11941
b6a5f39Thanks @Princesseuh! - Adds a newbuildOutputproperty to theastro:config:donehook returning the build output type.This can be used to know if the user's project will be built as a static site (HTML files), or a server-rendered site (whose exact output depends on the adapter).
Patch Changes
-
#11960
4410130Thanks @ascorbic! - Fixes an issue where the refresh context data was not passed correctly to content layer loaders -
#11952
50a0146Thanks @ascorbic! - Adds support for array patterns in the built-inglob()content collections loaderThe glob loader can now accept an array of multiple patterns as well as string patterns. This allows you to more easily combine multiple patterns into a single collection, and also means you can use negative matches to exclude files from the collection.
const probes = defineCollection({ // Load all markdown files in the space-probes directory, except for those that start with "voyager-" loader: glob({ pattern: ['*.md', '!voyager-*'], base: 'src/data/space-probes' }), schema: z.object({ name: z.string(), type: z.enum(['Space Probe', 'Mars Rover', 'Comet Lander']), launch_date: z.date(), status: z.enum(['Active', 'Inactive', 'Decommissioned']), destination: z.string(), operator: z.string(), notable_discoveries: z.array(z.string()), }), }); -
#11968
86ad1fdThanks @NikolaRHristov! - Fixes a typo in the server island JSDoc -
#11983
633eeaaThanks @uwej711! - Remove dependency on path-to-regexp
5.0.0-alpha.5
Major Changes
-
#11916
46ea29fThanks @bluwy! - Updates how thebuild.clientandbuild.serveroption values get resolved to match existing documentation. With this fix, the option values will now correctly resolve relative to theoutDiroption. So ifoutDiris set to./dist/nested/, then by default:build.clientwill resolve to<root>/dist/nested/client/build.serverwill resolve to<root>/dist/nested/server/
Previously the values were incorrectly resolved:
build.clientwas resolved to<root>/dist/nested/dist/client/build.serverwas resolved to<root>/dist/nested/dist/server/
If you were relying on the previous build paths, make sure that your project code is updated to the new build paths.
Minor Changes
-
#11875
a8a3d2cThanks @florian-lefebvre! - Adds a new propertyisPrerenderedto the globalsAstroandAPIContext. This boolean value represents whether or not the current page is prerendered:--- // src/pages/index.astro export const prerender = true; ---// src/middleware.js export const onRequest = (ctx, next) => { console.log(ctx.isPrerendered); // it will log true return next(); };
Patch Changes
-
#11927
5b4e3abThanks @florian-lefebvre! - Updates theenvconfiguration reference docs to include a full API reference forenvField. -
#11943
fa4671cThanks @sarah11918! - Updates error messages that assume content collections are located insrc/content/with more generic language
5.0.0-alpha.4
Major Changes
-
#11859
3804711Thanks @florian-lefebvre! - Changes the defaulttsconfig.jsonwith better defaults, and makessrc/env.d.tsoptionalAstro's default
tsconfig.jsonin starter examples has been updated to include generated types and exclude your build output. This means thatsrc/env.d.tsis only necessary if you have added custom type declarations or if you're not using atsconfig.jsonfile.Additionally, running
astro syncno longer creates, nor updates,src/env.d.tsas it is not required for type-checking standard Astro projects.To update your project to Astro's recommended TypeScript settings, please add the following
includeandexcludeproperties totsconfig.json:{ "extends": "astro/tsconfigs/base", + "include": [".astro/types.d.ts", "**/*"], + "exclude": ["dist"] }
Minor Changes
-
#11911
c3dce83Thanks @ascorbic! - The Content Layer API introduced behind a flag in 4.14.0 is now stable and ready for use in Astro v5.0.The new Content Layer API builds upon content collections, taking them beyond local files in
src/content/and allowing you to fetch content from anywhere, including remote APIs. These new collections work alongside your existing content collections, and you can migrate them to the new API at your own pace. There are significant improvements to performance with large collections of local files. For more details, see the Content Layer RFC.If you previously used this feature, you can now remove the
experimental.contentLayerflag from your Astro config:// astro.config.mjs import { defineConfig } from 'astro' export default defineConfig({ - experimental: { - contentLayer: true - } })Loading your content
The core of the new Content Layer API is the loader, a function that fetches content from a source and caches it in a local data store. Astro 4.14 ships with built-in
glob()andfile()loaders to handle your local Markdown, MDX, Markdoc, and JSON files:// src/content/config.ts import { defineCollection, z } from 'astro:content'; import { glob } from 'astro/loaders'; const blog = defineCollection({ // The ID is a slug generated from the path of the file relative to `base` loader: glob({ pattern: '**/*.md', base: './src/data/blog' }), schema: z.object({ title: z.string(), description: z.string(), publishDate: z.coerce.date(), }), }); export const collections = { blog };You can then query using the existing content collections functions, and use a simplified
render()function to display your content:--- import { getEntry, render } from 'astro:content'; const post = await getEntry('blog', Astro.params.slug); const { Content } = await render(entry); --- <Content />Creating a loader
You're not restricted to the built-in loaders – we hope you'll try building your own. You can fetch content from anywhere and return an array of entries:
// src/content/config.ts const countries = defineCollection({ loader: async () => { const response = await fetch('https://restcountries.com/v3.1/all'); const data = await response.json(); // Must return an array of entries with an id property, // or an object with IDs as keys and entries as values return data.map((country) => ({ id: country.cca3, ...country, })); }, // optionally add a schema to validate the data and make it type-safe for users // schema: z.object... }); export const collections = { countries };For more advanced loading logic, you can define an object loader. This allows incremental updates and conditional loading, and gives full access to the data store. It also allows a loader to define its own schema, including generating it dynamically based on the source API. See the the Content Layer API RFC for more details.
Sharing your loaders
Loaders are better when they're shared. You can create a package that exports a loader and publish it to npm, and then anyone can use it on their site. We're excited to see what the community comes up with! To get started, take a look at some examples. Here's how to load content using an RSS/Atom feed loader:
// src/content/config.ts import { defineCollection } from 'astro:content'; import { feedLoader } from '@ascorbic/feed-loader'; const podcasts = defineCollection({ loader: feedLoader({ url: 'https://feeds.99percentinvisible.org/99percentinvisible', }), }); export const collections = { podcasts };To learn more, see the Content Layer RFC.
Patch Changes
-
#11902
d63bc50Thanks @ascorbic! - Fixes case where content layer did not update during clean dev builds on Linux and Windows -
#11914
b5d827bThanks @ascorbic! - Exports types for allLoaderContextproperties fromastro/loadersto make it easier to use them in custom loaders. TheScopedDataStoreinterface (which was previously internal) is renamed toDataStore, to reflect the fact that it's the only public API for the data store.
5.0.0-alpha.3
Major Changes
-
#11861
3ab3b4eThanks @bluwy! - Cleans up Astro-specific metadata attached tovfile.datain Remark and Rehype plugins. Previously, the metadata was attached in different locations with inconsistent names. The metadata is now renamed as below:vfile.data.__astroHeadings->vfile.data.astro.headingsvfile.data.imagePaths->vfile.data.astro.imagePaths
The types of
imagePathshas also been updated fromSet<string>tostring[]. Thevfile.data.astro.frontmattermetadata is left unchanged.While we don't consider these APIs public, they can be accessed by Remark and Rehype plugins that want to re-use Astro's metadata. If you are using these APIs, make sure to access them in the new locations.
-
#11825
560ef15Thanks @bluwy! - Updates internal Shiki rehype plugin to highlight code blocks as hast (using Shiki'scodeToHast()API). This allows a more direct Markdown and MDX processing, and improves the performance when building the project, but may cause issues with existing Shiki transformers.If you are using Shiki transformers passed to
markdown.shikiConfig.transformers, you must make sure they do not use thepostprocesshook as it no longer runs on code blocks in.mdand.mdxfiles. (See the Shiki documentation on transformer hooks for more information).Code blocks in
.mdocfiles and<Code />component do not use the internal Shiki rehype plugin and are unaffected. -
#11819
2bdde80Thanks @bluwy! - Updates the Astro config loading flow to ignore processing locally-linked dependencies with Vite (e.g.npm link, in a monorepo, etc). Instead, they will be normally imported by the Node.js runtime the same way as other dependencies fromnode_modules.Previously, Astro would process locally-linked dependencies which were able to use Vite features like TypeScript when imported by the Astro config file.
However, this caused confusion as integration authors may test against a package that worked locally, but not when published. This method also restricts using CJS-only dependencies because Vite requires the code to be ESM. Therefore, Astro's behaviour is now changed to ignore processing any type of dependencies by Vite.
In most cases, make sure your locally-linked dependencies are built to JS before running the Astro project, and the config loading should work as before.
Patch Changes
-
#11878
334948cThanks @ascorbic! - Adds a new functionrefreshContentto theastro:server:setuphook that allows integrations to refresh the content layer. This can be used, for example, to register a webhook endpoint during dev, or to open a socket to a CMS to listen for changes.By default,
refreshContentwill refresh all collections. You can optionally pass aloadersproperty, which is an array of loader names. If provided, only collections that use those loaders will be refreshed. For example, A CMS integration could use this property to only refresh its own collections.You can also pass a
contextobject to the loaders. This can be used to pass arbitrary data, such as the webhook body, or an event from the websocket.{ name: 'my-integration', hooks: { 'astro:server:setup': async ({ server, refreshContent }) => { server.middlewares.use('/_refresh', async (req, res) => { if(req.method !== 'POST') { res.statusCode = 405 res.end('Method Not Allowed'); return } let body = ''; req.on('data', chunk => { body += chunk.toString(); }); req.on('end', async () => { try { const webhookBody = JSON.parse(body); await refreshContent({ context: { webhookBody }, loaders: ['my-loader'] }); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ message: 'Content refreshed successfully' })); } catch (error) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Failed to refresh content: ' + error.message })); } }); }); } } } -
Updated dependencies [
3ab3b4e,560ef15,3ab3b4e]:- @astrojs/markdown-remark@6.0.0-alpha.1
5.0.0-alpha.2
Major Changes
-
#11826
7315050Thanks @matthewp! - Deprecate Astro.globThe
Astro.globfunction has been deprecated in favor of Content Collections andimport.meta.glob.- If you want to query for markdown and MDX in your project, use Content Collections.
- If you want to query source files in your project, use
import.meta.glob(https://vitejs.dev/guide/features.html#glob-import).
Also consider using glob packages from npm, like fast-glob, especially if statically generating your site, as it is faster for most use-cases.
The easiest path is to migrate to
import.meta.globlike so:- const posts = Astro.glob('./posts/*.md'); + const posts = Object.values(import.meta.glob('./posts/*.md', { eager: true })); -
#11827
a83e362Thanks @matthewp! - Prevent usage ofastro:contentin the clientUsage of
astro:contentin the client has always been discouraged because it leads to all of your content winding up in your client bundle, and can possibly leaks secrets.This formally makes doing so impossible, adding to the previous warning with errors.
In the future Astro might add APIs for client-usage based on needs.
-
#11253
4e5cc5aThanks @kevinzunigacuellar! - Changes the data returned forpage.url.current,page.url.next,page.url.prev,page.url.firstandpage.url.lastto include the value set forbasein your Astro config.Previously, you had to manually prepend your configured value for
baseto the URL path. Now, Astro automatically includes yourbasevalue innextandprevURLs.If you are using the
paginate()function for "previous" and "next" URLs, remove any existingbasevalue as it is now added for you:--- export async function getStaticPaths({ paginate }) { const astronautPages = [{ astronaut: 'Neil Armstrong', }, { astronaut: 'Buzz Aldrin', }, { astronaut: 'Sally Ride', }, { astronaut: 'John Glenn', }]; return paginate(astronautPages, { pageSize: 1 }); } const { page } = Astro.props; // `base: /'docs'` configured in `astro.config.mjs` - const prev = "/docs" + page.url.prev; + const prev = page.url.prev; --- <a id="prev" href={prev}>Back</a>
Minor Changes
-
#11698
05139efThanks @ematipico! - Adds a new property to the globalsAstroandAPIContextcalledroutePattern. TheroutePatternrepresents the current route (component) that is being rendered by Astro. It's usually a path pattern will look like this:blog/[slug]:--- // src/pages/blog/[slug].astro const route = Astro.routePattern; console.log(route); // it will log "blog/[slug]" ---// src/pages/index.js export const GET = (ctx) => { console.log(ctx.routePattern); // it will log src/pages/index.js return new Response.json({ loreum: 'ipsum' }); };
Patch Changes
-
#11791
9393243Thanks @bluwy! - Updates Astro's default<script>rendering strategy and removes theexperimental.directRenderScriptoption as this is now the default behavior: scripts are always rendered directly. This new strategy prevents 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>, multiple scripts on a page are no longer bundled together, and the<script>tag may interfere with the CSS styling.As this is a potentially breaking change to your script behavior, please review your
<script>tags and ensure that they behave as expected.
5.0.0-alpha.1
Major Changes
-
#11798
e9e2139Thanks @matthewp! - Unflag globalRoutePriorityThe previously experimental feature
globalRoutePriorityis now the default in Astro 5.This was a refactoring of route prioritization in Astro, making it so that injected routes, file-based routes, and redirects are all prioritized using the same logic. This feature has been enabled for all Starlight projects since it was added and should not affect most users.
-
#11679
ea71b90Thanks @florian-lefebvre! - Theastro:envfeature introduced behind a flag in v4.10.0 is no longer experimental and is available for general use. If you have been waiting for stabilization before usingastro:env, you can now do so.This feature lets you configure a type-safe schema for your environment variables, and indicate whether they should be available on the server or the client.
To configure a schema, add the
envoption to your Astro config and define your client and server variables. If you were previously using this feature, please remove the experimental flag from your Astro config and move your entireenvconfiguration unchanged to a top-level option.import { defineConfig, envField } from 'astro/config'; export default defineConfig({ env: { schema: { API_URL: envField.string({ context: 'client', access: 'public', optional: true }), PORT: envField.number({ context: 'server', access: 'public', default: 4321 }), API_SECRET: envField.string({ context: 'server', access: 'secret' }), }, }, });You can import and use your defined variables from the appropriate
/clientor/servermodule:--- import { API_URL } from 'astro:env/client'; import { API_SECRET_TOKEN } from 'astro:env/server'; const data = await fetch(`${API_URL}/users`, { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_SECRET_TOKEN}`, }, }); --- <script> import { API_URL } from 'astro:env/client'; fetch(`${API_URL}/ping`); </script> -
#11788
7c0ccfcThanks @ematipico! - Updates the default value ofsecurity.checkOrigintotrue, which enables Cross-Site Request Forgery (CSRF) protection by default for pages rendered on demand.If you had previously configured
security.checkOrigin: true, you no longer need this set in your Astro config. This is now the default and it is safe to remove.To disable this behavior and opt out of automatically checking that the “origin” header matches the URL sent by each request, you must explicitly set
security.checkOrigin: false:export default defineConfig({ + security: { + checkOrigin: false + } }) -
#11741
6617491Thanks @bluwy! - Removes internal JSX handling and moves the responsibility to the@astrojs/mdxpackage directly. The following exports are also now removed:astro/jsx/babel.jsastro/jsx/component.jsastro/jsx/index.jsastro/jsx/renderer.jsastro/jsx/server.jsastro/jsx/transform-options.js
If your project includes
.mdxfiles, you must upgrade@astrojs/mdxto the latest version so that it doesn't rely on these entrypoints to handle your JSX. -
#11782
9a2aaa0Thanks @Princesseuh! - Makes thecompiledContentproperty of Markdown content an async function, this change should fix underlying issues where sometimes when using a custom image service and images inside Markdown, Node would exit suddenly without any error message.--- import * as myPost from "../post.md"; - const content = myPost.compiledContent(); + const content = await myPost.compiledContent(); --- <Fragment set:html={content} /> -
#11770
cfa6a47Thanks @Princesseuh! - Removed support for the Squoosh image service. As the underlying librarylibsquooshis no longer maintained, and the image service sees very little usage we have decided to remove it from Astro.Our recommendation is to use the base Sharp image service, which is more powerful, faster, and more actively maintained.
- import { squooshImageService } from "astro/config"; import { defineConfig } from "astro/config"; export default defineConfig({ - image: { - service: squooshImageService() - } });If you are using this service, and cannot migrate to the base Sharp image service, a third-party extraction of the previous service is available here: https://github.com/Princesseuh/astro-image-service-squoosh
5.0.0-alpha.0
Major Changes
-
#10742
b6fbdaaThanks @ematipico! - The lowest version of Node supported by Astro is now Node v18.17.1 and higher. -
#11715
d74617cThanks @Princesseuh! - Refactor the exported types from theastromodule. There should normally be no breaking changes, but if you relied on some previously deprecated types, these might now have been fully removed.In most cases, updating your code to move away from previously deprecated APIs in previous versions of Astro should be enough to fix any issues.
-
#11660
e90f559Thanks @bluwy! - Fixes attribute rendering for non-boolean HTML attributes with boolean values to match proper attribute handling in browsers.Previously, non-boolean attributes may not have included their values when rendered to HTML. In Astro v5.0, the values are now explicitly rendered as
="true"or="false"In the following
.astroexamples, onlyallowfullscreenis a boolean attribute:<!-- src/pages/index.astro --><!-- `allowfullscreen` is a boolean attribute --> <p allowfullscreen={true}></p> <p allowfullscreen={false}></p> <!-- `inherit` is *not* a boolean attribute --> <p inherit={true}></p> <p inherit={false}></p> <!-- `data-*` attributes are not boolean attributes --> <p data-light={true}></p> <p data-light={false}></p>Astro v5.0 now preserves the full data attribute with its value when rendering the HTML of non-boolean attributes:
<p allowfullscreen></p> <p></p> <p inherit="true"></p> - <p inherit></p> + <p inherit="false"></p> - <p data-light></p> + <p data-light="true"></p> - <p></p> + <p data-light="false"></p>If you rely on attribute values, for example to locate elements or to conditionally render, update your code to match the new non-boolean attribute values:
- el.getAttribute('inherit') === '' + el.getAttribute('inherit') === 'false' - el.hasAttribute('data-light') + el.dataset.light === 'true' -
#11714
8a53517Thanks @matthewp! - Remove support for functionPerRouteThis change removes support for the
functionPerRouteoption both in Astro and@astrojs/vercel.This option made it so that each route got built as separate entrypoints so that they could be loaded as separate functions. The hope was that by doing this it would decrease the size of each function. However in practice routes use most of the same code, and increases in function size limitations made the potential upsides less important.
Additionally there are downsides to functionPerRoute, such as hitting limits on the number of functions per project. The feature also never worked with some Astro features like i18n domains and request rewriting.
Given this, the feature has been removed from Astro.