fix: always run basicAuth route rule first#4204
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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)
📝 WalkthroughWalkthroughDeterministically orders route rules by an optional numeric Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/runtime/internal/route-rules.ts (1)
93-96: Consider trimming the new explanatory comment block.These lines mostly restate behavior already captured by
RouteRuleOrderand test coverage.As per coding guidelines "Do not add comments explaining what the line does unless prompted."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime/internal/route-rules.ts` around lines 93 - 96, Remove or shorten the explanatory comment block above RouteRuleOrder in route-rules.ts so it doesn't restate behavior already captured by the enum and tests; keep only a concise one-line note (if any) that clarifies the ordering intent (e.g., "Execution order for route rule middleware; lower runs first") and remove the extra sentence about basicAuth ordering since that logic is enforced by RouteRuleOrder and covered by tests (refer to the RouteRuleOrder symbol to locate the code).src/types/route-rules.ts (1)
37-40:MatchedRouteRule.orderis currently dead API surface.
getRouteRules()insrc/runtime/internal/app.tsorders middleware viaRouteRuleOrder[rule.name]and never consults this field, so type/API and runtime behavior can diverge. Consider removingorderfor now or wiring it into the comparator.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/types/route-rules.ts` around lines 37 - 40, MatchedRouteRule.order is unused at runtime; update getRouteRules in src/runtime/internal/app.ts to consult MatchedRouteRule.order when sorting instead of only using RouteRuleOrder[rule.name]. Change the comparator in getRouteRules to compute each rule's sort key as (rule.order ?? RouteRuleOrder[rule.name] ?? 0) so explicit per-rule order overrides the lookup, and leave the type MatchedRouteRule.order in src/types/route-rules.ts as-is; ensure comparison remains stable for equal keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/runtime/internal/route-rules.ts`:
- Around line 93-96: Remove or shorten the explanatory comment block above
RouteRuleOrder in route-rules.ts so it doesn't restate behavior already captured
by the enum and tests; keep only a concise one-line note (if any) that clarifies
the ordering intent (e.g., "Execution order for route rule middleware; lower
runs first") and remove the extra sentence about basicAuth ordering since that
logic is enforced by RouteRuleOrder and covered by tests (refer to the
RouteRuleOrder symbol to locate the code).
In `@src/types/route-rules.ts`:
- Around line 37-40: MatchedRouteRule.order is unused at runtime; update
getRouteRules in src/runtime/internal/app.ts to consult MatchedRouteRule.order
when sorting instead of only using RouteRuleOrder[rule.name]. Change the
comparator in getRouteRules to compute each rule's sort key as (rule.order ??
RouteRuleOrder[rule.name] ?? 0) so explicit per-rule order overrides the lookup,
and leave the type MatchedRouteRule.order in src/types/route-rules.ts as-is;
ensure comparison remains stable for equal keys.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 609e80cb-6a78-4c13-8536-29d2a4247a15
📒 Files selected for processing (5)
src/runtime/internal/app.tssrc/runtime/internal/route-rules.tssrc/types/route-rules.tstest/fixture/nitro.config.tstest/tests.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/runtime/internal/route-rules.ts (1)
86-87: Remove the explanatory inline comment block.The added comment explains behavior rather than encoding intent in code/tests, which conflicts with this repo’s style rule.
As per coding guidelines
src/**/*.{ts,js}: “Do not add comments explaining what the line does unless prompted”.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime/internal/route-rules.ts` around lines 86 - 87, Remove the explanatory inline comment block that begins "// Must run before `redirect`/`proxy`/`cache`..." in route-rules.ts; instead encode the behavior via tests or explicit code assertions (e.g., add a unit/integration test or an ordering constant) so intent is enforced in code, not explained by a comment. Locate the comment near the routing rules/middleware ordering setup in route-rules.ts (the section that references redirect/proxy/cache) and delete it, and if needed add a test or an ordering constant to ensure unauthorized requests are processed before redirect/proxy/cache.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/runtime/internal/route-rules.ts`:
- Around line 86-87: Remove the explanatory inline comment block that begins "//
Must run before `redirect`/`proxy`/`cache`..." in route-rules.ts; instead encode
the behavior via tests or explicit code assertions (e.g., add a unit/integration
test or an ordering constant) so intent is enforced in code, not explained by a
comment. Locate the comment near the routing rules/middleware ordering setup in
route-rules.ts (the section that references redirect/proxy/cache) and delete it,
and if needed add a test or an ordering constant to ensure unauthorized requests
are processed before redirect/proxy/cache.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a3be77d-4b94-47b1-a1c2-2f41022707c2
📒 Files selected for processing (5)
src/runtime/internal/app.tssrc/runtime/internal/route-rules.tssrc/types/route-rules.tstest/presets/netlify.test.tstest/presets/vercel.test.ts
✅ Files skipped from review due to trivial changes (1)
- src/runtime/internal/app.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/types/route-rules.ts
commit: |
This PR makes sure
basicAuthroute rule (first introduced via #4049 in v3.0.260311-beta) always runs first before others like proxy, etc.