Skip to content
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

Merged
merged 7 commits into from
Dec 21, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to 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

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added the bug Something isn't working label Dec 19, 2022
@danielroe danielroe self-assigned this Dec 19, 2022
@danielroe danielroe requested a review from pi0 December 19, 2022 16:52
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)
Copy link
Member

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.

Copy link
Member Author

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: "/(.*)",
dest: "/__nitro",
},
...(!nitro.options.routeRules['/**']?.cache || !(nitro.options.routeRules['/**'].cache.swr || nitro.options.routeRules['/**']?.cache.static)
Copy link
Member

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
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #768 (4679953) into main (3d48658) will decrease coverage by 0.00%.
The diff coverage is 90.00%.

@@            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              
Impacted Files Coverage Ξ”
src/presets/vercel.ts 77.11% <84.00%> (-1.73%) ⬇️
src/presets/netlify.ts 59.14% <100.00%> (+2.09%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pi0
Copy link
Member

pi0 commented Dec 21, 2022

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 :)

@pi0 pi0 merged commit 567b6df into main Dec 21, 2022
@pi0 pi0 deleted the fix/vercel-order branch December 21, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants