Parse <StarlightPage />
frontmatter asynchronously
#2279
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
frontmatter
containing typereference()
causes an error in pages that use the<StarlightPage />
component. #2270This PR updates how the frontmatter data passed down to the
<StarlightPage />
component is parsed. Starting with Astro 4.14.0, schemas containing collection references contains an async transform which would failed to be parsed due to our usage of ZodsafeParse()
instead ofsafeParseAsync()
.I decided to create a new
parseAsyncWithFriendlyErrors()
instead of always parsing schemas asynchrounously asparseWithFriendlyErrors()
is used in the pluginsetup
hookupdateConfig
option and I did not want to change that behavior. The new function is now only used in this specific case.Regarding testing, I decided to not add a test as we cannot really easily have a unit test with a custom schema using
extend
and having an E2E test for this would require using a different Astro version. Creating a unit test simply callingparseAsyncWithFriendlyErrors()
with a schema containing an async refinement or transform doesn't provide much value imo. Let me know if you think otherwise.Altho, I used the reproduction in #2270 and tested the fix using Astro
4.13.4
and the latest version and both are now working as expected.