Repository navigation
fix(bundler): resolve dynamic ogImage in useSeoMeta transform - #770
Conversation
…form The useSeoMeta->useHead AST transform only expanded ogImage/twitterImage object and array literals. A dynamic value (ref, computed, getter, identifier) was inlined as a single content field, so at runtime the resolved object serialized to [object Object] instead of expanding into og:image, og:image:width, etc. Bail such calls to runtime unpackMeta, which already handles them. Also expand static media object literals and fix the url sub-key, which was emitted as og:image:url instead of og:image. Resolves #769
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds MEDIA_KEYS-aware transform for useSeoMeta: statically expands object/array literal media entries (ogImage, ogVideo, ogAudio, twitterImage) into multiple meta tags and falls back to leaving the call for runtime unpacking when shapes are dynamic; also preserves aliased imports when transforms bail. ChangesMedia key static expansion with dynamic fallback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle Size Analysis
|
- preserve aliased imports (useSeoMeta as usm) when a media call bails, which previously left the kept call site unbound (ReferenceError) - bail object literals with getters/setters/methods/computed keys instead of splicing invalid syntax into content - bail non-primitive literal media values (e.g. regexp) that would diverge from runtime - map secureUrl to :secure_url in static media objects, matching runtime
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bundler/test/useSeoMetaTransform.test.ts (1)
222-232: ⚡ Quick winAdd the missing “method” bailout case to match the test intent.
This block claims getter/method/computed-key coverage, but currently only asserts getter and computed-key forms.
Suggested test addition
it('bails media objects with getters/methods/computed keys', async () => { // These can't be reproduced as plain `key: value` tags, so the call must go to runtime. expect(await transform([ 'import { useSeoMeta } from \'unhead\'', 'useSeoMeta({ ogImage: { get url() { return \'/o.png\' } } })', ])).toBeUndefined() + expect(await transform([ + 'import { useSeoMeta } from \'unhead\'', + 'useSeoMeta({ ogImage: { url() { return \'/o.png\' } } })', + ])).toBeUndefined() expect(await transform([ 'import { useSeoMeta } from \'unhead\'', 'useSeoMeta({ ogImage: { [key]: \'/o.png\' } })', ])).toBeUndefined() })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bundler/test/useSeoMetaTransform.test.ts` around lines 222 - 232, The test currently checks getter and computed-key bailouts but misses a "method" object form; add a third assertion inside the same it('bails media objects with getters/methods/computed keys', ...) that calls transform with code containing useSeoMeta({ ogImage: { method() { return '/o.png' } } }) and expect the result toBeUndefined(), referencing the existing transform helper and the useSeoMeta invocation so the test covers the method bailout case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/bundler/test/useSeoMetaTransform.test.ts`:
- Around line 222-232: The test currently checks getter and computed-key
bailouts but misses a "method" object form; add a third assertion inside the
same it('bails media objects with getters/methods/computed keys', ...) that
calls transform with code containing useSeoMeta({ ogImage: { method() { return
'/o.png' } } }) and expect the result toBeUndefined(), referencing the existing
transform helper and the useSeoMeta invocation so the test covers the method
bailout case.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2da73da3-1489-43f6-9401-cf3f74c04a90
📒 Files selected for processing (2)
packages/bundler/src/unplugin/UseSeoMetaTransform.tspackages/bundler/test/useSeoMetaTransform.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bundler/src/unplugin/UseSeoMetaTransform.ts
🔗 Linked issue
Resolves #769
❓ Type of change
📚 Description
The
useSeoMeta->useHeadbuild transform only expandedogImage/twitterImagewhen written as object or array literals. A dynamic value (ref,computed, a getter, or a plain identifier) was inlined as a singlecontentfield, so at runtime the resolved object serialized to[object Object]instead of expanding intoog:image,og:image:width, etc.The runtime (
unpackMetaviaFlatMetaPlugin) already handles these dynamic values correctly; only the build transform diverged.UseSeoMetaTransformnow detects the media keys (ogImage,ogVideo,ogAudio,twitterImage) and:useSeoMeta(...)is preserved and resolved at runtime),ogImage: { url, width }into separate tags, matching runtime,urlsub-key, which was emitted asog:image:urlinstead ofog:image.Verified against runtime output: dynamic getters/refs/computed for
ogImage(array and object) and the corrected static expansion now match the SSR result. Covered by new and updated tests inuseSeoMetaTransform.test.ts.Summary by CodeRabbit
Improvements
Bug Fixes
Tests