routeRules: the h3 preMerge fallback warning is not actionable in Nitro

Open
#5,048 0 comments 0 reactions 0 assignees View on GitHub

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

dx route-rules
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 /**.md pair 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 routeRules compilation 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 /**.md to 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

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.