Skip to content

fix(assets): prevent circular dependency deadlock with SVG in content collections#15603

Merged
Princesseuh merged 5 commits into
withastro:mainfrom
0xRozier:fix/issue-15575-tla-svg-content-collection-deadlock
Feb 26, 2026
Merged

fix(assets): prevent circular dependency deadlock with SVG in content collections#15603
Princesseuh merged 5 commits into
withastro:mainfrom
0xRozier:fix/issue-15575-tla-svg-content-collection-deadlock

Conversation

@0xRozier

Copy link
Copy Markdown
Contributor

Summary

Fixes #15575

  • Preserve astroContentImageFlag through the Vite resolution pipeline in vite-plugin-content-assets.ts so downstream plugins can detect content collection images
  • Return plain ImageMetadata for content collection SVGs in vite-plugin-assets.ts instead of creating full Astro components (which import createComponent from the server runtime and cause a circular module dependency deadlock with TLA)

Root Cause

When SVG images are used in content collection image() fields:

  1. content-assets.mjs imports them with ?astroContentImageFlag
  2. The content asset plugin stripped this flag during resolution
  3. The assets ESM plugin didn't know the SVG came from a content collection, so it called makeSvgComponent() which imports from runtime/server/index.js
  4. Combined with top-level await (TLA) in page components, this created a circular dependency deadlock causing Node.js to silently exit with code 0

Fix

The astroContentImageFlag is now preserved through resolution so the assets plugin can distinguish content collection SVGs (which only need metadata) from directly imported SVGs (which need full component rendering).

Test plan

  • New regression test: content-collection-tla-svg.test.js (YAML collection + SVG image() field + TLA with getCollection)
  • Existing core-image tests pass (100/100)
  • Existing core-image-svg tests pass (11/11)
  • Existing content-layer tests pass (59/59)

🤖 Generated with Claude Code

…content collections (#15575)

When SVG images are used in content collection `image()` fields combined with
top-level await (TLA), the build would silently exit due to a circular module
dependency deadlock. SVGs were being converted to full Astro components (importing
`createComponent` from the server runtime) even when only metadata was needed for
content collection data.

The fix preserves the `astroContentImageFlag` through the Vite resolution pipeline
so that the `astro:assets:esm` plugin can detect content collection SVGs and return
plain `ImageMetadata` instead of creating full components, breaking the circular
dependency chain.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@changeset-bot

changeset-bot Bot commented Feb 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7568f86

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 Feb 20, 2026
@codspeed-hq

codspeed-hq Bot commented Feb 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing 0xRozier:fix/issue-15575-tla-svg-content-collection-deadlock (7568f86) with main (7150a2e)

Open in CodSpeed

@matthewp

Copy link
Copy Markdown
Contributor

Looks pretty good! Can you add a changeset? pnpm changeset

@0xRozier

Copy link
Copy Markdown
Contributor Author

Looks pretty good! Can you add a changeset? pnpm changeset

No problem, I'll try to do this this sunday (I hope).

@0xRozier

Copy link
Copy Markdown
Contributor Author

Looks pretty good! Can you add a changeset? pnpm changeset

Should be good now, hope you'll like it

Comment thread packages/astro/src/assets/vite-plugin-assets.ts
Comment thread packages/astro/src/assets/vite-plugin-assets.ts

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks good. I would like to rephrase the changeset to make it more end-user-friendly, and we could apply the small optimisation

Comment thread .changeset/fix-svg-content-collection-deadlock.md Outdated
Comment thread packages/astro/src/assets/vite-plugin-assets.ts
Comment thread packages/astro/src/content/vite-plugin-content-assets.ts Outdated
- Reword changeset to be more end-user-friendly
- Mutate resolved.id directly instead of spreading a new object

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Princesseuh
Princesseuh merged commit 5bc2b2c into withastro:main Feb 26, 2026
27 checks passed
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.

TLA regression in v6

5 participants