-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
support for legacy content collections removed #12376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
3d722b8
07221b6
ea94f56
2471a2b
9ff6f61
fddbb86
fb4c121
29fb6aa
41f864b
1a71b64
e849055
171c416
5adf67e
be4b2c1
b342d32
192934b
147afa5
9bb8dc3
935b6d6
4649681
01342b0
7f20e74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,137 @@ The following features have now been entirely removed from the code base and can | |
|
|
||
| Projects now containing these removed features will be unable to build, and there will no longer be any supporting documentation prompting you to remove these features. | ||
|
|
||
|
|
||
| ### Removed: legacy content collections | ||
|
|
||
| <SourcePR number="14407" title="fix: remove legacy content collections"/> | ||
|
|
||
| In Astro 5.x, it was still possible to use [the Content Collections API first introduced in Astro v2.0](https://astro.build/blog/introducing-content-collections/), either through a `legacy` configuration flag or via built-in backwards compatibility. These methods allowed you to upgrade to Astro v5 even if you were not yet ready or able to update your content collections to the new Content Layer API. | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Astro v6.0 removes this previously deprecated Content Collections API support entirely, including the `legacy.collections` flag.** All content collections must now use the Content Layer API introduced in Astro v5.0 that powers all content collections. No backwards compatibility support is available. | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### What should I do? | ||
|
|
||
| If you had previously enabled the legacy flag, you must remove it. | ||
|
|
||
| ```ts title="astro.config.mjs" del={5} | ||
| import { defineConfig } from 'astro/config'; | ||
|
|
||
| export default defineConfig({ | ||
| legacy: { | ||
| collections: true, | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| Additionally, if you did not upgrade your collections for Astro v5.0, ensure that your content collections are **fully updated** for the updated API. | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Astro v5.x included some automatic backwards compatibility to allow content collections to continue to work even if they had not been updated to use the new API. Therefore, your v5 collections may contain one or more legacy features that need updating to the newer API for v6, even if your project was previously error-free. | ||
|
|
||
| If you have content collections errors after upgrading to v6, use the following list to help you identify and upgrade any legacy features that may exist in your code. | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ##### If you have... | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add the error messages in here too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this could be helpful, or at least the error code so someone can easily identify the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea! Would the implementation PR be a comprehensive list of all the ones they might encounter? I'm seeing:
What we did for v5 was mock up the new errors / config in the v5 branch (duplicating what would be generated from the JSDoc), so we should probabably manually recreate those errors in this PR, too. If they end up not being identical, then a ci PR will be generated to align them. Just copied the entire jsdoc from entries here for now
export const LegacyContentConfigError = { /**
export const ContentCollectionMissingLoader = { /**
export const ContentCollectionInvalidType = { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are also some places where we just log a warning rather than throwing an error: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could add a more searchable name there too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't get to the spot in that link directly from the link, because GitHub can't handle the PR. 😅 Which file are warnings included in so I can get there myself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I've updated the text to refer to both error messages and warnings and we can do further edits on top of that! I'm not sure they all need to be spelled out here, since in theory those should have their own explanations and guidance. To avoid this content being overwhelming, I think just a mention that "if you get warnings/errors, these are the likely places to check" is fine here! If people are not getting these errors/warnings, no need to be spelling them out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just meant adding the specific codes such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I think I get it. Let me cook! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, here's my current draft to address this:
@ascorbic I didn't notice specific errors (either in your removing legacy support PR, nor existing ones) for the situation where:
So, those two don't have associated errors mentioned here. Do we have such errors, and if not, should we? |
||
|
|
||
| <details> | ||
| <summary>no content collections configuration file</summary> | ||
| Create `src/content.config.ts` and [define your collections](/en/guides/content-collections/#defining-collections) in it. | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>a configuration file located at `src/content/config.ts`</summary> | ||
| Rename and move this file to `src/content.config.ts` | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>a collection that does not define a `loader`</summary> | ||
|
|
||
| Import [Astro's built-in `glob()` loader](/en/guides/content-collections/#built-in-loaders) and define the `pattern` and `base` for your collection entries: | ||
|
|
||
| ```ts ins={3,6} | ||
| // src/content.config.ts | ||
| import { defineCollection, z } from 'astro:content'; | ||
| import { glob } from 'astro/loaders'; | ||
|
|
||
| const blog = defineCollection({ | ||
| loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: "./src/data/blog" }), | ||
| schema: z.object({ | ||
| title: z.string(), | ||
| description: z.string(), | ||
| pubDate: z.coerce.date(), | ||
| updatedDate: z.coerce.date().optional(), | ||
| }), | ||
| }); | ||
| ``` | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>a collection that defines a collection type (`type: 'content'` or `type: 'data'`)</summary> | ||
| There are no longer different types of collections. This must be deleted from your collection definition. | ||
|
|
||
| ```ts del={7} | ||
sarah11918 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // src/content.config.ts | ||
| import { defineCollection, z } from 'astro:content'; | ||
| import { glob } from 'astro/loaders'; | ||
|
|
||
| const blog = defineCollection({ | ||
| // For content layer you no longer define a `type` | ||
| type: 'content', | ||
| loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: "./src/data/blog" }), | ||
| schema: z.object({ | ||
| title: z.string(), | ||
| description: z.string(), | ||
| pubDate: z.coerce.date(), | ||
| updatedDate: z.coerce.date().optional(), | ||
| }), | ||
| }); | ||
| ``` | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>legacy collection querying methods `getDataEntryById()` and `getEntryBySlug()`</summary> | ||
| Replace both methods with [`getEntry()`](/en/reference/modules/astro-content/#getentry). | ||
|
|
||
| </details> | ||
|
|
||
| <details> | ||
| <summary>legacy collection querying and rendering methods that depend on a `slug` property</summary> | ||
| Previously the `id` was based on the filename, and there was a `slug` property that could be used in a URL. Now the [CollectionEntry type](/en/reference/modules/astro-content/#collectionentry) `id` is a slug. If you need access to the filename (previously available as the `id`) use the `filePath` property. Replace instances of `slug` with `id`.: | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```astro ins={6} del={5} title="src/pages/[slug].astro" | ||
| --- | ||
| export async function getStaticPaths() { | ||
| const posts = await getCollection('blog'); | ||
| return posts.map((post) => ({ | ||
| params: { slug: post.slug }, | ||
| params: { slug: post.id }, | ||
| props: post, | ||
| })); | ||
| } | ||
| --- | ||
| ``` | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary>content rendered using `entry.render()`</summary> | ||
| Collection entries no longer have a render() method. Instead, import the `render()` function from `astro:content` and use `render(entry)`: | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```astro title="src/pages/index.astro" ins=", render" del={6} ins={7} | ||
| --- | ||
| import { getEntry, render } from 'astro:content'; | ||
|
|
||
| const post = await getEntry('blog', params.slug); | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const { Content, headings } = await post.render(); | ||
| const { Content, headings } = await render(post); | ||
| --- | ||
| <Content /> | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| <ReadMore> See [the Astro v5 upgrade guide](/en/guides/upgrade-to/v5/#legacy-v20-content-collections-api) for previous guidance about backwards compatibility of legacy collections in Astro v5 and upgrading to the new Content Layer API.</ReadMore> | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ### Removed: `<ViewTransitions />` component | ||
|
|
||
| <SourcePR number="14400" title="Remove deprecated ViewTransitions component"/> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| # NOTE: This file is auto-generated from 'scripts/error-docgen.mjs' | ||
| # Do not make edits to it directly, they will be overwritten. | ||
| # Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| # Translators, please remove this note and the <DontEditWarning/> component. | ||
|
|
||
| title: Content collection invalid type. | ||
| i18nReady: true | ||
| githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| --- | ||
|
|
||
| import DontEditWarning from '~/components/DontEditWarning.astro' | ||
|
|
||
| <DontEditWarning /> | ||
|
|
||
|
|
||
| > Invalid collection type "data". Remove the type from your collection definition in your content config file. | ||
| ### What went wrong? | ||
|
|
||
| Content collections should no longer have a type field. Remove this field from your content config file. | ||
|
|
||
| See the [Astro 6 migration guide](https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections) for more information. | ||
|
Check failure on line 23 in src/content/docs/en/reference/errors/content-collection-invalid-type.mdx
|
||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| # NOTE: This file is auto-generated from 'scripts/error-docgen.mjs' | ||
| # Do not make edits to it directly, they will be overwritten. | ||
| # Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| # Translators, please remove this note and the <DontEditWarning/> component. | ||
|
|
||
| title: Content collection missing loader. | ||
| i18nReady: true | ||
| githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| --- | ||
|
|
||
| import DontEditWarning from '~/components/DontEditWarning.astro' | ||
|
|
||
| <DontEditWarning /> | ||
|
|
||
|
|
||
| > Collections must have a loader defined. Check your collection definitions in your content config file. | ||
| ### What went wrong? | ||
|
|
||
| A legacy content config file was found. Move the file to `src/content.config.ts` and update any collection definitions if needed. | ||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| A content collection is missing a loader definition. Make sure that each collection in your content config file has a loader. | ||
|
|
||
| **See Also:** | ||
| - [Content collections configuration](https://docs.astro.build/en/guides/content-collections/#defining-the-collection-loader) | ||
|
Check failure on line 25 in src/content/docs/en/reference/errors/content-collection-missing-loader.mdx
|
||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| # NOTE: This file is auto-generated from 'scripts/error-docgen.mjs' | ||
| # Do not make edits to it directly, they will be overwritten. | ||
| # Instead, change this file: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| # Translators, please remove this note and the <DontEditWarning/> component. | ||
|
|
||
| title: Legacy content config error. | ||
| i18nReady: true | ||
| githubURL: https://github.com/withastro/astro/blob/main/packages/astro/src/core/errors/errors-data.ts | ||
| --- | ||
|
|
||
| import DontEditWarning from '~/components/DontEditWarning.astro' | ||
|
|
||
| <DontEditWarning /> | ||
|
|
||
|
|
||
| > Legacy content config file found. | ||
| ### What went wrong? | ||
|
|
||
| A legacy content config file was found. Move the file to `src/content.config.ts` and update any collection definitions if needed. | ||
|
|
||
| See the [Astro 6 migration guide](https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections) for more information. | ||
|
Check failure on line 23 in src/content/docs/en/reference/errors/legacy-content-config-error.mdx
|
||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **See Also:** | ||
| - [Content collections configuration](https://docs.astro.build/en/guides/content-collections/#the-collection-config-file) | ||
|
Check failure on line 26 in src/content/docs/en/reference/errors/legacy-content-config-error.mdx
|
||
sarah11918 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||

Uh oh!
There was an error while loading. Please reload this page.