astro 2.0.0
Note This is a detailed changelog of all changes in Astro v2.
See our upgrade guide for an overview of steps needed to upgrade an existing project.
Major Changes
-
#5687
e2019be6fThanks @bholmesdev! - Give remark and rehype plugins access to user frontmatter via frontmatter injection. This meansdata.astro.frontmatteris now the complete Markdown or MDX document's frontmatter, rather than an empty object.This allows plugin authors to modify existing frontmatter, or compute new properties based on other properties. For example, say you want to compute a full image URL based on an
imageSrcslug in your document frontmatter:export function remarkInjectSocialImagePlugin() { return function (tree, file) { const { frontmatter } = file.data.astro; frontmatter.socialImageSrc = new URL(frontmatter.imageSrc, 'https://my-blog.com/').pathname; }; }When using Content Collections, you can access this modified frontmatter using the
remarkPluginFrontmatterproperty returned when rendering an entry.Migration instructions
Plugin authors should now check for user frontmatter when applying defaults.
For example, say a remark plugin wants to apply a default
titleif none is present. Add a conditional to check if the property is present, and update if none exists:export function remarkInjectTitlePlugin() { return function (tree, file) { const { frontmatter } = file.data.astro; + if (!frontmatter.title) { frontmatter.title = 'Default title'; + } } }This differs from previous behavior, where a Markdown file's frontmatter would always override frontmatter injected via remark or reype.
-
#5891
05caf445dThanks @bholmesdev! - Remove deprecated Markdown APIs from Astro v0.X. This includesgetHeaders(), the.astroproperty for layouts, and therawContent()andcompiledContent()error messages for MDX. -
#5778
49ab4f231Thanks @bluwy! - Remove proload to load the Astro config. It will now use NodeJS and Vite to load the config only. -
#5728
8fb28648fThanks @natemoo-re! - The previously experimental features--experimental-error-overlayand--experimental-prerender, both added in v1.7.0, are now the default.You'll notice that the error overlay during
astro devhas a refreshed visual design and provides more context for your errors.The
prerenderfeature is now enabled by default when usingoutput: 'server'. To prerender a particular page, addexport const prerender = trueto your frontmatter.Warning Integration authors that previously relied on the exact structure of Astro's v1.0 build output may notice some changes to our output file structure. Please test your integrations to ensure compatability. Users that have configured a custom
vite.build.rollupOptions.output.chunkFileNamesshould ensure that their Astro project is configured as an ESM Node project. Either include"type": "module"in your rootpackage.jsonfile or use the.mjsextension forchunkFileNames. -
#5782
1f92d64eaThanks @Princesseuh! - Remove support for Node 14. Minimum supported Node version is now >=16.12.0 -
#5771
259a539d7Thanks @matthewp! - Removes support for astroFlavoredMarkdownIn 1.0 Astro moved the old Astro Flavored Markdown (also sometimes called Components in Markdown) to a legacy feature. This change removes the
legacy.astroFlavoredMarkdownoption completely.In 2.0 this feature will not be available in Astro at all. We recommend migration to MDX for those were still using this feature in 1.x.
-
#5941
304823811Thanks @bholmesdev! - Content collections: Introduce a newslugfrontmatter field for overriding the generated slug. This replaces the previousslug()collection config option from Astro 1.X and the 2.0 beta.When present in a Markdown or MDX file, this will override the generated slug for that entry.
# src/content/blog/post-1.md --- title: Post 1 + slug: post-1-custom-slug ---Astro will respect this slug in the generated
slugtype and when using thegetEntryBySlug()utility:--- import { getEntryBySlug } from 'astro:content'; // Retrieve `src/content/blog/post-1.md` by slug with type safety const post = await getEntryBySlug('blog', 'post-1-custom-slug'); ---Migration
If you relied on the
slug()config option, you will need to move all custom slugs toslugfrontmatter properties in each collection entry.Additionally, Astro no longer allows
slugas a collection schema property. This ensures Astro can manage theslugproperty for type generation and performance. Remove this property from your schema and any relevantslug()configuration:const blog = defineCollection({ schema: z.object({ - slug: z.string().optional(), }), - slug({ defaultSlug, data }) { - return data.slug ?? defaultSlug; - }, }) -
#5753
302e0ef8fThanks @bluwy! - Default preview host tolocalhostinstead of127.0.0.1. This allows the static server and integration preview servers to serve under ipv6. -
#5716
dd56c1941Thanks @bluwy! - Remove MDX Fragment hack. This was used by@astrojs/mdxto access theFragmentcomponent, but isn't required anymore since@astrojs/mdxv0.12.1. -
#5584
9963c6e4d& #5842c4b0cb8bfThanks @wulinsheng123 and @natemoo-re! - Breaking Change: client assets are built to an_astrodirectory in the build output directory. Previously these were built to various locations, includingassets/,chunks/and the root of build output.You can control this location with the new
buildconfiguration option namedassets. -
#5893
be901dc98Thanks @matthewp! - RenamegetEntrytogetEntryBySlugThis change moves
getEntrytogetEntryBySlugand accepts a slug rather than an id.In order to improve support in
[id].astroroutes, particularly in SSR where you do not know what the id of a collection is. UsinggetEntryBySluginstead allows you to map the[id]param in your route to the entry. You can use it like this:--- import { getEntryBySlug } from 'astro:content'; const entry = await getEntryBySlug('docs', Astro.params.id); if (!entry) { return new Response(null, { status: 404, }); } --- <!-- You have an entry! Use it! --> -
#5685
f6cf92b48Thanks @bluwy! - Upgrade to Vite 4. Please see its migration guide for more information. -
#5724
16c7d0bfdThanks @bluwy! - Remove outdated Vue info log. RemovetoStringsupport forRenderTemplateResult. -
#5684
a9c292026& #576993e633922Thanks @bholmesdev! - Refine Markdown and MDX configuration options for ease-of-use.-
Markdown
-
Replace the
extendDefaultPluginsoption with agfmboolean and asmartypantsboolean. These are enabled by default, and can be disabled to remove GitHub-Flavored Markdown and SmartyPants. -
Ensure GitHub-Flavored Markdown and SmartyPants are applied whether or not custom
remarkPluginsorrehypePluginsare configured. If you want to apply custom plugins and remove Astro's default plugins, manually setgfm: falseandsmartypants: falsein your config.
-
-
Migrate
extendDefaultPluginstogfmandsmartypantsYou may have disabled Astro's built-in plugins (GitHub-Flavored Markdown and Smartypants) with the
extendDefaultPluginsoption. This has now been split into 2 flags to disable each plugin individually:-
markdown.gfmto disable GitHub-Flavored Markdown -
markdown.smartypantsto disable SmartyPants// astro.config.mjs import { defineConfig } from 'astro/config'; export default defineConfig({ markdown: { -
extendDefaultPlugins: false,
-
smartypants: false,
-
gfm: false, } });
Additionally, applying remark and rehype plugins **no longer disables** `gfm` and `smartypants`. You will need to opt-out manually by setting `gfm` and `smartypants` to `false`.
-
-
MDX
-
Support all Markdown configuration options (except
drafts) from your MDX integration config. This includessyntaxHighlightingandshikiConfigoptions to further customize the MDX renderer. -
Simplify
extendPluginsto anextendMarkdownConfigoption. MDX options will default to their equivalent in your Markdown config. By settingextendMarkdownConfigto false, you can "eject" to set your own syntax highlighting, plugins, and more.
-
-
Migrate MDX's
extendPluginstoextendMarkdownConfigYou may have used the
extendPluginsoption to manage plugin defaults in MDX. This has been replaced by 3 flags:extendMarkdownConfig(trueby default) to toggle Markdown config inheritance. This replaces theextendPlugins: 'markdown'option.gfm(trueby default) andsmartypants(trueby default) to toggle GitHub-Flavored Markdown and SmartyPants in MDX. This replaces theextendPlugins: 'defaults'option.
-
-
#5717
a3a7fc929Thanks @bluwy! - Removestyle.postcssAstro config. Refactor tailwind integration to configure throughviteinstead. Also disablesautoprefixerin dev. -
#5825
52209ca2aThanks @bholmesdev! - Baseline the experimentalcontentCollectionsflag. You're free to remove this from your astro config!import { defineConfig } from 'astro/config'; export default defineConfig({ - experimental: { contentCollections: true } }) -
#5707
5eba34fccThanks @bluwy! - Remove deprecatedAstroglobal APIs, includingAstro.resolve,Astro.fetchContent, andAstro.canonicalURL.-
Astro.resolveYou can resolve asset paths using
importinstead. For example:--- import 'style.css'; import imageUrl from './image.png'; --- <img src={imageUrl} />See the v0.25 migration guide for more information.
-
Astro.fetchContentUse
Astro.globinstead to fetch markdown files, or migrate to the Content Collections feature.let allPosts = await Astro.glob('./posts/*.md'); -
Astro.canonicalURLUse
Astro.urlinstead to construct the canonical URL.const canonicalURL = new URL(Astro.url.pathname, Astro.site);
-
-
#5608
899214298Thanks @konojunya! - A trailing slash will not be automatically appended toimport.meta.env.SITE. Instead, it will be the value of thesiteconfig as is. This may affect usages of${import.meta.env.SITE}image.png, which will need to be updated accordingly. -
#5707
5eba34fccThanks @bluwy! - RemovebuildConfigoption parameter from integrationastro:build:starthook in favour of thebuild.configoption in theastro:config:setuphook.export default function myIntegration() { return { name: 'my-integration', hooks: { 'astro:config:setup': ({ updateConfig }) => { updateConfig({ build: { client: '...', server: '...', serverEntry: '...', }, }); }, }, }; }
Minor Changes
-
#5901
a342a486cThanks @bluwy! - The fallback Svelte preprocessor will only be applied if a custompreprocessoption is not passed to thesvelte()integration option, or in thesvelte.config.jsfile.To support IDE autocompletion, or if you're migrating from
@astrojs/sveltev1, you can create asvelte.config.jsfile with:import { vitePreprocess } from '@astrojs/svelte'; export default { preprocess: vitePreprocess(), };This file will also be generated by
astro add svelteby default. -
#5786
c2180746bThanks @bholmesdev! - Move generated content collection types to a.astrodirectory. This replaces the previously generatedsrc/content/types.generated.d.tsfile.If you're using Git for version control, we recommend ignoring this generated directory by adding
.astroto your .gitignore.Astro will also generate the TypeScript reference path to include
.astrotypes in your project. This will update your project'ssrc/env.d.tsfile, or write one if none exists. -
#5826
840412128Thanks @bholmesdev! - Allow Zod objects, unions, discriminated unions, intersections, and transform results as content collection schemas.Migration
Astro requires a
z.object(...)wrapper on all content collection schemas. Update your content collections config like so:// src/content/config.ts import { z, defineCollection } from 'astro:content'; const blog = defineCollection({ - schema: { + schema: z.object({ ... }) -
#5823
1f49cddf9Thanks @delucis! - Generate content types when runningastro check -
#5832
2303f9514Thanks @HiDeoo! - Add support for serving well-known URIs with the @astrojs/node SSR adapter
Patch Changes
-
#5855
16dc36a87Thanks @natemoo-re! - Remove legacy compiler error handling -
#5822
01f3f463bThanks @natemoo-re! - Fix edge case with bundle generation by emitting a single chunk for pages -
#5803
ae8a012a7Thanks @bluwy! - Upgrade compiler and handle breaking changes -
#5840
cf2de5422Thanks @chenxsan! - Persist CLI flags when restarting the dev server -
#5884
ce5c5dbd4Thanks @MoustaphaDev! - Add a theme toggle button to the error overlay -
#5824
665a2c222Thanks @bholmesdev! - Better handle content type generation failures:- Generate types when content directory is empty
- Log helpful error when running
astro syncwithout a content directory - Avoid swallowing
config.tssyntax errors from Vite
-
#5499
4987d6f44Thanks @bluwy! - Handle custom injected entry files during build -
#5734
55cea0a9dThanks @natemoo-re! - Fixprerenderwhen used withgetStaticPaths -
#5845
e818cc046Thanks @bluwy! - Fix importing client-side components with alias -
#5849
8c100a6feThanks @bluwy! - Handle server restart from Vite plugins -
#5756
116d8835cThanks @matthewp! - Fix for hoisted scripts in project with spaces in the file path -
#5917
7325df412Thanks @natemoo-re! - Fix duplicate CSS in dev mode whenvite.css.devSourcemapis provided -
#5743
2a5786419Thanks @Princesseuh! - Add error location during build for user-generated errors -
#5761
fa8c131f8Thanks @bholmesdev! - Add helpful error message when the MDX integration is missing. -
#5896
64b8082e7Thanks @natemoo-re! - Update@astrojs/compilertov1.0.0 -
#5829
23dc9ea96Thanks @giuseppelt! - FixCode.astroshiki css class replace logic -
#5836
63a6ceb38Thanks @natemoo-re! - Fix route matching when path includes special characters -
#5909
5fd9208d4Thanks @jasikpark! - Update compiler to 1.0.1 -
#5852
3a00ecb3eThanks @rishi-raj-jain! - Respectvite.envPrefixif provided -
#5872
b66d7195cThanks @bluwy! - EnableskipLibCheckby default -
Updated dependencies [
93e633922,e2019be6f,1f92d64ea,12f65a4d5,46ecd5de3,16107b6a1,c55fbcb8e,a9c292026,1f92d64ea,52209ca2a,7572f7402]:- @astrojs/markdown-remark@2.0.0
- @astrojs/telemetry@2.0.0
- @astrojs/webapi@2.0.0