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: separate image extraction from schema parsing in content layer #11884

Merged
merged 3 commits into from
Sep 1, 2024

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Aug 30, 2024

Changes

Currently image imports in the content layer are extracted during schema parsing with the image() helper. This caused a problem when entries were reused from the data store, as they would need to be re-parsed if the images were to be found. This is what the glob loader was doing, causing #11737, where the transformed object does not match the schema.

This was quite a tricky one to fix, because of the way the image helper is so closely tied to zod parsing. The fix is to split the detection from the asset handling part: the image helper still prefixes the values with __ASTRO_IMAGE_ so that they can be identified in the runtime and replaced. However the image helper no longer registers the asset itself. Instead, the assets are registered when the entry is added to the store: the data is traversed, and any images are identified by their prefix, registered as assets and added as a new top-level field on the object. This means that re-used entries don't need to be re-parsed, as the assets are already known and can be re-registered instead.

Fixes #11737

Testing

Fixtures updated and new tests added.

Docs

Copy link

changeset-bot bot commented Aug 30, 2024

🦋 Changeset detected

Latest commit: aa43a77

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 Aug 30, 2024
@ascorbic ascorbic merged commit e450704 into main Sep 1, 2024
13 checks passed
@ascorbic ascorbic deleted the asset-cl-handling branch September 1, 2024 09:05
@astrobot-houston astrobot-houston mentioned this pull request Aug 30, 2024
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.

Content layer validates already validated objects causing transforms to fail a validation
2 participants