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