Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3d722b8
removed content collections
sarah11918 Sep 22, 2025
07221b6
Merge branch 'v6' into content-collections-removed
sarah11918 Sep 22, 2025
ea94f56
links back to v5 content
sarah11918 Sep 22, 2025
2471a2b
proper link syntax
sarah11918 Sep 22, 2025
9ff6f61
Merge branch 'v6' into content-collections-removed
sarah11918 Sep 24, 2025
fddbb86
remove legacy flag documentation
sarah11918 Sep 24, 2025
fb4c121
🌭 details? do we like this?
sarah11918 Sep 24, 2025
29fb6aa
add the implementation PR and some stronger wording
sarah11918 Sep 24, 2025
41f864b
add removing legacy flag
sarah11918 Sep 24, 2025
1a71b64
don't focus on collection API names, just legacy/new
sarah11918 Sep 25, 2025
e849055
add placeholder error messages
sarah11918 Sep 25, 2025
171c416
relative links
sarah11918 Sep 25, 2025
5adf67e
links to Content Layer API deep dive blog post and content collection…
sarah11918 Sep 26, 2025
be4b2c1
Merge branch 'v6' into content-collections-removed
sarah11918 Oct 17, 2025
b342d32
Polishing of upgrade guidance, fix an error message
sarah11918 Oct 17, 2025
192934b
Apply suggestions from Armand code review
sarah11918 Oct 18, 2025
147afa5
added error messages to summaries of things to check for
sarah11918 Oct 18, 2025
9bb8dc3
fix links
sarah11918 Oct 18, 2025
935b6d6
fix error link
sarah11918 Oct 18, 2025
4649681
missing parenthesis
sarah11918 Oct 18, 2025
01342b0
two commas, but one line suggestion so I'm declaring it ONE error fix…
sarah11918 Oct 18, 2025
7f20e74
Merge branch 'v6' into content-collections-removed
sarah11918 Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions src/content/docs/en/guides/upgrade-to/v6.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,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 original 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 existing content collections to those powered by the new Content Layer API.

**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](https://astro.build/blog/content-layer-deep-dive/) that powers all content collections. No backwards compatibility support is available.

#### 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 new API.

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](/en/reference/error-reference/#content-collection-errors) or warnings after upgrading to v6, use the following list to help you identify and upgrade any legacy features that may exist in your code.

##### If you have...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add the error messages in here too

Copy link
Member

Choose a reason for hiding this comment

The 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 details to expand.

Copy link
Member Author

@sarah11918 sarah11918 Sep 25, 2025

Choose a reason for hiding this comment

The 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:

  • 'LegacyContentConfigError'
  • 'ContentCollectionMissingLoader'
  • 'ContentCollectionInvalidType'

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
  • @docs
  • @message
  • Example error message:
  • Found legacy content config file in "src/content/config.ts". Please move this file to "src/content.config.ts" and ensure each collection has a loader defined.
  • @description
  • 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 for more information.
    */

export const LegacyContentConfigError = {
name: 'LegacyContentConfigError',
title: 'Legacy content config file found.',
message: (filename: string) =>
Found legacy content config file in "${filename}". Please move this file to "src/content.config.${filename.split('.').at(-1)}" and ensure each collection has a loader defined.,
hint: 'See https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on updating collections.',
} satisfies ErrorData;

/**

  • @docs
  • @message
  • Example error message:
  • Collections must have a loader defined. Check your collection definitions in your content config file.
  • @description
  • A content collection is missing a loader definition. Make sure that each collection in your content config file has a loader.
  • See the Content collections documentation for more information.
    */

export const ContentCollectionMissingLoader = {
name: 'ContentCollectionMissingLoader',
title: 'Content collection is missing a loader definition.',
message: (file = 'your content config file') =>
Collections must have a \loader` defined. Check your collection definitions in ${file}.`,
hint: 'See https://docs.astro.build/en/guides/content-collections/ for more information on content loaders and https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on migrating from legacy collections.',
} satisfies ErrorData;

/**

  • @docs
  • @message
  • Example error message:
  • Invalid collection type "data". Remove the type from your collection definition in your content config file.
  • @description
  • Content collections should no longer have a type field. Remove this field from your content config file.
  • See the Astro 6 migration guide for more information.
    */

export const ContentCollectionInvalidType = {
name: 'ContentCollectionInvalidType',
title: 'Content collection has an invalid type field.',
message: (type: string, file = 'your content config file') =>
Invalid collection type "${type}". Remove the type from your collection definition in ${file}.,
hint: 'See https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections for more information on migrating from legacy collections.',
} satisfies ErrorData;

Copy link
Contributor

Choose a reason for hiding this comment

The 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:

https://github.com/withastro/astro/pull/14407/files#diff-04e44d3cde1db4d52d43a7732043f5239e1c49479b993e3dda7486399a5a51fbR214-R223

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add a more searchable name there too.

Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

@sarah11918 sarah11918 Sep 26, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant adding the specific codes such as ContentCollectionMissingLoader to the section, to make each section more searchable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I get it. Let me cook!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, here's my current draft to address this:

image

@ascorbic I didn't notice specific errors (either in your removing legacy support PR, nor existing ones) for the situation where:

  • there is NO content config file at all
  • they are not importing and using the render function (and are instead calling it on the entry)

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` / ([`LegacyContentConfigError`](/en/reference/errors/legacy-content-config-error/))</summary>
Rename and move this file to `src/content.config.ts`
</details>

<details>
<summary>a collection that does not define a `loader`/ ([`ContentCollectionMissingALoaderError`](/en/reference/errors/content-collection-missing-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'`) / ([`ContentCollectionInvalidTypeError`](/en/reference/errors/content-collection-invalid-type/))</summary>
There are no longer different types of collections. This must be deleted from your collection definition.

```ts del={7}
// 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()` / ([`GetEntryDeprecationError`](/en/reference/errors/get-entry-deprecation-error/))</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 / ([`ContentSchemaContainsSlugError`](/en/reference/errors/content-schema-contains-slug-error/))</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](/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`:

```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)`:

```astro title="src/pages/index.astro" ins=", render" del={6} ins={7}
---
import { getEntry, render } from 'astro:content';

const post = await getEntry('pages', 'homepage');

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 full step-by-step instructions for upgrading legacy collections to the new Content Layer API.</ReadMore>


### Removed: `<ViewTransitions />` component

<SourcePR number="14400" title="Remove deprecated ViewTransitions component"/>
Expand Down
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](/en/guides/upgrade-to/v6/#removed-legacy-content-collections) for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# 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 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](/en/guides/content-collections/#defining-the-collection-loader)
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](/en/guides/upgrade-to/v6/#removed-legacy-content-collections) for more information.

**See Also:**
- [Content collections configuration](/en/guides/content-collections/#the-collection-config-file)
44 changes: 3 additions & 41 deletions src/content/docs/en/reference/legacy-flags.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,11 @@ title: Legacy flags
i18nReady: true
---

import Since from '~/components/Since.astro'

To help some users migrate between versions of Astro, we occasionally introduce `legacy` flags.

These flags allow you to opt in to some deprecated or otherwise outdated behavior of Astro
in the latest version, so that you can continue to upgrade and take advantage of new Astro releases until you are able to fully update your project code.

import Since from '~/components/Since.astro'

## Collections

<p>

**Type:** `boolean`<br />
**Default:** `false`<br />
<Since v="5.0.0" />
</p>

Enable legacy behavior for content collections (as used in Astro v2 through v4)

```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
legacy: {
collections: true
}
});
```

If enabled, `data` and `content` collections (only) are handled using the legacy content collections implementation. Collections with a `loader` (only) will continue to use the Content Layer API instead. Both kinds of collections may exist in the same project, each using their respective implementations.

The following limitations continue to exist:

- Any legacy (`type: 'content'` or `type: 'data'`) collections must continue to be located in the `src/content/` directory.
- These legacy collections will not be transformed to implicitly use the `glob()` loader, and will instead be handled by legacy code.
- Collections using the Content Layer API (with a `loader` defined) are forbidden in `src/content/`, but may exist anywhere else in your project.

When you are ready to remove this flag and migrate to the new Content Layer API for your legacy collections, you must define a collection for any directories in `src/content/` that you want to continue to use as a collection. It is sufficient to declare an empty collection, and Astro will implicitly generate an appropriate definition for your legacy collections:

```js
// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({ })

export const collections = { blog };
```
There are currently no legacy flags available. When new legacy flags become available, instructions for removing them and upgrading to the latest features of Astro will be listed below.