Skip to content
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

fix: make reference() a sync transform #12781

Merged
merged 3 commits into from
Jan 2, 2025
Merged

fix: make reference() a sync transform #12781

merged 3 commits into from
Jan 2, 2025

Conversation

ascorbic
Copy link
Contributor

Changes

Currently the transform used in reference() is async. This was a change with content collections to allow the store to be loaded. However this caused an issue during JSON schema generation when combined with default(). See withastro/docs#10362 where this reported as part of a docs PR.

This PR updates the transform to instead preload the store and then make the transform itself sync.

Testing

Updated fixture to use the reference().default() syntax that previously broke.

Docs

Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: 0ba701e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Dec 19, 2024
Copy link

codspeed-hq bot commented Dec 19, 2024

CodSpeed Performance Report

Merging #12781 will not alter performance

Comparing no-async-schema (0ba701e) with main (73b6c8b)

Summary

✅ 4 untouched benchmarks

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I would provide a more actionable message. Code wise, it seems good

if (!store) {
ctx.addIssue({
code: ZodIssueCode.custom,
message: `**${ctx.path.join('.')}:** Reference to ${collection} could not be resolved. Store not available.`,
Copy link
Member

Choose a reason for hiding this comment

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

I would add a more actionable message. If the user encounters this error, what should they do? File an issue? Purge the store? We should provide an escape hatch to our users

@ematipico ematipico merged commit 96c4b92 into main Jan 2, 2025
15 of 16 checks passed
@ematipico ematipico deleted the no-async-schema branch January 2, 2025 09:49
@astrobot-houston astrobot-houston mentioned this pull request Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants