-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(netlify, vercel): order route rules from most specific + avoid double-rendering root #768
Conversation
src/presets/netlify.ts
Outdated
nitro.options.routeRules | ||
).filter(([_, routeRules]) => routeRules.headers)) { | ||
const rules = Object.entries(nitro.options.routeRules) | ||
.sort((a, b) => b[0].split("/").length - a[0].split("/").length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small issue with sorting /test/a
is more specific than /test/*
but if * is before, it remains before and shadows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch - thank you β€οΈ
src/presets/vercel.ts
Outdated
src: "/(.*)", | ||
dest: "/__nitro", | ||
}, | ||
...(!nitro.options.routeRules['/**']?.cache || !(nitro.options.routeRules['/**'].cache.swr || nitro.options.routeRules['/**']?.cache.static) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain it better in line above? Do we need to also handle other route rules for catch-all such as headers?
Codecov Report
@@ Coverage Diff @@
## main #768 +/- ##
==========================================
- Coverage 70.07% 70.07% -0.01%
==========================================
Files 57 57
Lines 5209 5229 +20
Branches 568 575 +7
==========================================
+ Hits 3650 3664 +14
- Misses 1550 1556 +6
Partials 9 9
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thanks for the updates. About sorting, it should be same as radix3 structure while hoisting placeholders in regex, might be less accurate i think we can merge it to unblock downstream issue for nuxt.com :) |
π Linked issue
β Type of change
π Description
This orders route rules within vercel + netlify presets so that (particularly glob) rules do not shadow rules below them. In addition, if the default vercel route rule is
/**: { static: true }
we don't also need to output a second, SSR rule.cc: @antfu - if you clone this and checkout commit c7f8f39, then run
vitest run -u
the test passes and the inline snapshots are not updated. I've also noticed some other weird issues like a different snapshot within a file being updated than the one it corresponds to (e.g. the next snapshot below).π Checklist