-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Content layer schema references randomly break #12680
Comments
I started experiencing this too after upgrading to Astro 5. It feels like some sort of race condition, where one collections entries aren't being processed before the other collection references them or something? If I change the reference to an old one, run astro dev, then kill it and change it back to the new one, it works. |
Not quite the same bug, but likely related as it also looks like a race condition somewhere:
When editing a // ...
export const BlogSchema = z.object({
title: z.string(),
tags: z.array(z.string()),
image: z.string().optional(),
description: z.string(),
date: z.date().transform((val) => new Date(val)),
growth: GrowthSchema.default("seed"),
related: z.array(reference("blog")).optional(),
});
const blogCollection = defineCollection({
loader: glob({ pattern: "**/[^_]*.md", base: "./src/data/blog" }),
schema: BlogSchema,
});
export const collections = {
blog: blogCollection,
}; The glob loader effectively detects the change and fires a reload on the browser, but the development server seems not be be ready instantly, and I need to refresh it manually a second time to get the actual content. The reloaded content also sometimes doesn't match the updated one (the old version is still being considered as "current" in the cache or something like that) After removing the |
Could any of the people reporting this confirm whether this is present in the latest version of Astro? We've made a few changes to prevent content collection race conditions so a lot of these sort of issues are now working. |
@ascorbic i can confirm that if I add new entry into let’s say tag collection and at the same time reference it from another collection entry let’s say post and run build I will get invalid reference error if I first add new tag, then run build, then reference new tag in post and build again everything works Astro version is 5.1.3 |
hi, i just verified on astro v5.1.5 and i get the same errors:
|
2 of my projects are running into the same issue. Any time I update something connected to a reference, it breaks the dev server.
Astro v5.1.7 const blogCollection = defineCollection({
loader: glob({ pattern: "**/[^_]*{md,mdx}", base: "./src/data/blog" }),
schema: ({ image }) =>
z.object({
title: z.string(),
description: z.string(),
// commenting out the authors reference for now
// authors: z.array(reference("authors")),
heroImage: image(),
}),
});
// authors
const authorsCollection = defineCollection({
loader: glob({ pattern: "**/[^_]*{md,mdx}", base: "./src/data/authors" }),
schema: ({ image }) =>
z.object({
name: z.string(),
avatar: image(),
}),
}); |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When editing content files and changing the names of referenced id's a lot occasionally astro will lock up and not allow the site to be built with an error like this:
The category
core
has been verified to exist and is defined properly in a yaml file../content/categories.yaml:
./src/content.config.ts:
./content/features/core/shards.md:
This is really hard to reproduce, but it has happened to me twice now in the last 3 days after my V5 migration, once initially while setting up the glob and file loaders, and another while simply modifying the names of categories. When these instances occur, not even reverting the project back to a time it was functional via git allows for it to build. The only solution I have found after many hours of nothing was this:
category: reference("categories"),
I feel this is a bug because nothing is changing at all about the schema, yet it can go from not building at all to building perfectly fine.
What's the expected result?
The website should build and not get locked up randomly on reference data updates.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-chwz8xrn?file=src%2Fcontent.config.ts
Participation
The text was updated successfully, but these errors were encountered: