Repository navigation
fix: merge dev route rule instead of replacing user rules - #950
Conversation
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #950 +/- ##
==========================================
- Coverage 70.55% 70.12% -0.43%
==========================================
Files 15 15
Lines 781 780 -1
Branches 214 214
==========================================
- Hits 551 547 -4
- Misses 195 200 +5
+ Partials 35 33 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
In dev, the public asset strategy assigns the font cache rule straight to
nuxt.options.routeRules['/_fonts/**']:This PR uses
extendRouteRulesfrom@nuxt/kitinstead.Why
The assignment replaces anything the user set for
/_fonts/**inrouteRules, and it only happens in dev. A user rule on that path, like customheaders(CORS for fonts loaded cross-origin) or a key another module reads, disappears in dev but still applies in production. You get no warning, and dev behaves differently from prod.We hit this with @nuxtjs/better-auth. Our app protects
/**with an auth route rule, and better-auth refuses to start when an auth-protected route also has a cache rule. The fonts dev rule inherited the/**auth. The natural fix,'/_fonts/**': { auth: false }inrouteRules, got wiped by this assignment, so we had to add it back in anitro:confighook. better-auth has since exempted/_fonts(nuxt-modules/better-auth#504), so that case no longer blocks us, but the overwrite still drops any other user rule on the path.extendRouteRulesmerges withdefuand defaults tooverride: false, so keys the user set win and the cache rule only fills in what's missing. It ships in@nuxt/kit4.6.2 (the^4.6.2range in package.json) and in the 5.x nightly. @nuxt/scripts uses it for the same dev cache rule on its assets path (packages/script/src/assets.ts), so the two modules now match.One small difference:
extendRouteRuleswrites the rule to bothnuxt.options.routeRulesandnuxt.options.nitro.routeRules, where the old code only wrotenuxt.options.routeRules. Without a user rule, the result is the same cache rule as before.Test
I added a case to
test/asset-strategy.test.ts. It setsrouteRules: { '/_fonts/**': { headers: { 'x-test': '1' } } }in dev and checks that the rule keeps the header and gets the cache rule. It fails onmain(the header is dropped) and passes with this change.🤖 Generated with Claude Code