mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
fix: defer check for schema references to content layer collections (#12097)
* fix: defer check for schema references * More comments
This commit is contained in:
parent
f06feee7c4
commit
11d447f66b
2 changed files with 11 additions and 12 deletions
5
.changeset/bright-swans-shout.md
Normal file
5
.changeset/bright-swans-shout.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes error where references in content layer schemas sometimes incorrectly report as missing
|
|
@ -599,16 +599,9 @@ export function createReference({ lookupMap }: { lookupMap: ContentLookupMap })
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// We won't throw if the collection is missing, because it may be a content layer collection and the store may not yet be populated.
|
||||||
|
// If it is an object then we're validating later in the build, so we can check the collection at that point.
|
||||||
|
|
||||||
// A reference object might refer to an invalid collection, because when we convert it we don't have access to the store.
|
|
||||||
// If it is an object then we're validating later in the pipeline, so we can check the collection at that point.
|
|
||||||
if (!lookupMap[collection] && !collectionIsInStore) {
|
|
||||||
ctx.addIssue({
|
|
||||||
code: ZodIssueCode.custom,
|
|
||||||
message: `**${flattenedErrorPath}:** Reference to ${collection} invalid. Collection does not exist or is empty.`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return lookup;
|
return lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,9 +616,10 @@ export function createReference({ lookupMap }: { lookupMap: ContentLookupMap })
|
||||||
}
|
}
|
||||||
return { id: lookup, collection };
|
return { id: lookup, collection };
|
||||||
}
|
}
|
||||||
|
// If the collection is not in the lookup map or store, it may be a content layer collection and the store may not yet be populated.
|
||||||
if (!lookupMap[collection] && store.collections().size === 0) {
|
// If the store has 0 or 1 entries it probably means that the entries have not yet been loaded.
|
||||||
// If the collection is not in the lookup map or store, it may be a content layer collection and the store may not yet be populated.
|
// The store may have a single entry even if the collections have not loaded, because the top-level metadata collection is generated early.
|
||||||
|
if (!lookupMap[collection] && store.collections().size <= 1) {
|
||||||
// For now, we can't validate this reference, so we'll optimistically convert it to a reference object which we'll validate
|
// For now, we can't validate this reference, so we'll optimistically convert it to a reference object which we'll validate
|
||||||
// later in the pipeline when we do have access to the store.
|
// later in the pipeline when we do have access to the store.
|
||||||
return { id: lookup, collection };
|
return { id: lookup, collection };
|
||||||
|
|
Loading…
Add table
Reference in a new issue