@@ -599,16 +599,9 @@ export function createReference({ lookupMap }: { lookupMap: ContentLookupMap })
599
599
} ) ;
600
600
return ;
601
601
}
602
+ // 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.
603
+ // If it is an object then we're validating later in the build, so we can check the collection at that point.
602
604
603
- // A reference object might refer to an invalid collection, because when we convert it we don't have access to the store.
604
- // If it is an object then we're validating later in the pipeline, so we can check the collection at that point.
605
- if ( ! lookupMap [ collection ] && ! collectionIsInStore ) {
606
- ctx . addIssue ( {
607
- code : ZodIssueCode . custom ,
608
- message : `**${ flattenedErrorPath } :** Reference to ${ collection } invalid. Collection does not exist or is empty.` ,
609
- } ) ;
610
- return ;
611
- }
612
605
return lookup ;
613
606
}
614
607
@@ -623,9 +616,10 @@ export function createReference({ lookupMap }: { lookupMap: ContentLookupMap })
623
616
}
624
617
return { id : lookup , collection } ;
625
618
}
626
-
627
- if ( ! lookupMap [ collection ] && store . collections ( ) . size === 0 ) {
628
- // 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.
619
+ // 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.
620
+ // If the store has 0 or 1 entries it probably means that the entries have not yet been loaded.
621
+ // The store may have a single entry even if the collections have not loaded, because the top-level metadata collection is generated early.
622
+ if ( ! lookupMap [ collection ] && store . collections ( ) . size <= 1 ) {
629
623
// For now, we can't validate this reference, so we'll optimistically convert it to a reference object which we'll validate
630
624
// later in the pipeline when we do have access to the store.
631
625
return { id : lookup , collection } ;
0 commit comments