fix: pass query params to OG image ISR function on Vercel#2432
fix: pass query params to OG image ISR function on Vercel#2432alexdln merged 5 commits intonpmx-dev:mainfrom
Conversation
Vercel's ISR `passQuery` defaults to `false`, which strips all query parameters before passing the request to the serverless function. This caused the compare page OG image to always render the empty state because the function never received `packages=zustand,redux` or the `_query` parameter that nuxt-og-image relies on. Closes npmx-dev#2431 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a new Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
nuxt.config.ts (1)
132-135: Add query parameter whitelist to explicitly constrain OG image cache variation
passQuery: truecorrectly makes query parameters available to the OG image handler. However, to ensure robust caching behaviour and prevent unintended cache fragmentation, explicitly specify which query parameters should affect the cache key usingallowQuery. By default, query parameters are ignored for cache keying unless listed inallowQuery, so adding this constraint makes the caching intent clear and ensures only the parameters the handler actually needs will vary the cache.Suggested hardening
'/__og-image__/**': { isr: { expiration: 3600, passQuery: true, + allowQuery: ['packages', '_query'], }, },Verify which query parameters the OG image handler requires and update the
allowQuerylist accordingly.
Restrict cache variation to only the query params the OG handler needs, preventing cache fragmentation from arbitrary query params. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Overall, it's a standard solution. The only thing I doubt is that there can be any number of these parameters and we could exceed the limits (incl. with different params order). On the other hand, we also have an infinite number of packages and it's fine there. I think we can try it and if anything happens we'll roll it back and make a universal image p.s. can we add sorting here so that at least we don't store different images with the same content depending on the order? |
Keep the default ISR config for all other OG images and only enable passQuery + allowQuery for the compare page OG image route. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Good point! |
12bcad6 to
795810a
Compare
Sorting ensures ?packages=zustand,redux and ?packages=redux,zustand produce the same OG image URL and share one ISR cache entry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
795810a to
bc19494
Compare
|
Thanks for the fix 🤍 |
Summary
passQuery: trueto the/__og-image__/**ISR route rulepassQuerydefaults tofalse, which strips all query parameters before passing the request to the serverless functionpackages=zustand,reduxor the_queryparameter thatnuxt-og-imagerelies onRoot cause
Vercel's prerender config has a
passQueryoption that defaults tofalse. Without it, the ISR function receives the request with query params stripped — so the OG image handler always fetched/compare(no packages) instead of/compare?packages=zustand,redux.Test plan
/compare?packages=zustand,redux/__og-image__/image/compare/og.html?packages=zustand,redux&_query=%7B%22packages%22:%22zustand,redux%22%7Dshows package namesCloses #2431