routeRules: the h3 preMerge fallback warning is not actionable in Nitro
Maintainers usually reply within 2 days
Nobody has claimed this yet.
- #5169 by @draarivpatel-ui — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 49/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start with src/build/virtual/routing.ts, where Nitro calls compileRouteRules with preMerge: true, and trace how that setting reaches route rule compilation. Check the routing tests for coverage of overlapping rules and the warning behavior. Done means a Nitro user has an actionable way to handle this warning, with tests covering the chosen behavior.
Written by the indexing model from the issue text.
Description
Describe the bug
Nitro compiles routeRules with compileRouteRules(nitro.options.routeRules, { ..., preMerge: true }) (src/build/virtual/routing.ts) and has no option to change it. When two rules partially overlap, for example /assets/** and /**.md with the same headers, h3 logs this on every dev start and on each build that compiles the routing module:
[h3] rules: compiler: preMerge could not be applied — falling back to plain compilation.
[h3] rules: preMerge: `/assets/**` and `/**.md` partially overlap — the most specific match is ambiguous. Split the overlap into explicit rules or disable preMerge.
Neither suggestion works for a Nitro user:
- preMerge cannot be disabled from the Nitro config.
- Adding an explicit rule for the intersection (
/assets/**.md) does not remove the warning, because the original/assets/**and/**.mdpair is still compared and is still a partial overlap.
The fallback itself is fine: the generated code is identical to preMerge: false, so the only effect is a warning the user cannot act on. It also hides real h3 warnings in the same output.
Reproduction
With h3 2.0.8 (the version Nitro 3.0.261103-rc installs):
import { compileRouteRules } from "h3/rules/compiler";
const headers = { headers: { "x-content-type-options": "nosniff" } };
const rules = { "/assets/**": headers, "/**.md": headers };
const merged = compileRouteRules(rules, { preMerge: true }); // logs the warning above
const plain = compileRouteRules(rules, { preMerge: false }); // no warning
console.log(merged === plain); // true
compileRouteRules({ ...rules, "/assets/**.md": headers }, { preMerge: true }); // same warning
In a Nitro app, the same happens with routeRules: { "/assets/**": { headers }, "/**.md": { headers } }.
Possible improvements
- Expose an option to opt out of preMerge (for example under
routeRulescompilation settings), so the h3 hint becomes actionable. - Or lower the message to a debug log when the fallback is behaviorally equivalent, as in the case above.
- Or adjust the hint to point to a fix that works, which is removing the partial overlap itself (for example scoping
/**.mdto known prefixes such as/en/**.md).
- Dominant language
- TypeScript
- Stars
- 11.5k
- Forks
- 968
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 64
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nitrojs/nitro
-
pending triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 2 days
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPossibly taken @draarivpatel-ui claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
pending triage
Difficulty 5/5 Over a week Newbie friendliness 30/100
nitrojs/nitro#5205 · 1 reaction ·
Maintainers usually reply within 2 days
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ranxianglei/billion-context#8319 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JimLiu/open-artifact#126 ·
-
bug repro-ready
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
mksglu/context-mode#1454 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#98 ·
Maintainers usually reply within 1 day
-
Add: KCM True crimeOpenapproved check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day