route-pattern@0.19.0
Breaking Changes📦 remixView on GitHub →
⚠ 4 breaking✨ 7 features🐛 3 fixes🔧 13 symbols
Summary
This release introduces significant breaking changes related to case sensitivity handling and AST structure for route patterns, alongside performance improvements for matchers and better error reporting for href generation.
⚠️ Breaking Changes
- The `RoutePatternOptions` type has been removed. The `ignoreCase` option now only applies to `pathname` in `RoutePattern` construction and no longer affects `search` matching.
- The `ignoreCase` field on `RoutePattern` instances has been removed. Case sensitivity must now be specified via the `ignoreCase` option passed to `RoutePattern.match`, `ArrayMatcher` constructor, or `TrieMatcher` constructor.
- The structure of param tokens within `RoutePattern.ast.{hostname,pathname}.tokens` has changed. Param tokens now contain a `name: string` field instead of `nameIndex: number`. If iterating over params, use the new `.params` getter on the AST segment.
- The `meta` property on the results of `RoutePattern.match` and `Matcher.match` has been renamed to `paramsMeta`.
Migration Steps
- If you relied on `RoutePatternOptions`, remove it and pass `ignoreCase` directly to `RoutePattern` constructor if needed, noting it only affects pathname matching.
- Update code referencing `RoutePattern.ignoreCase` or the `ignoreCase` option in matchers/pattern matching to use the new options passed to `.match()` or constructors.
- Update code accessing param tokens in `RoutePattern.ast.{hostname,pathname}.tokens` to use `token.name` instead of accessing `paramNames` via `token.nameIndex`. Alternatively, use the new `.params` getter.
- Rename usages of `RoutePatternMatch['meta']` and `Match['meta']` to `RoutePatternMatch['paramsMeta']` and `Match['paramsMeta']` respectively.
- When calling `RoutePattern.href`, remove checks for extra parameters if you wish to pass them without causing a type error.
✨ New Features
- `RoutePattern.match` now accepts an optional `ignoreCase` argument to control case sensitivity during matching.
- Both `ArrayMatcher` and `TrieMatcher` constructors now accept an optional `ignoreCase` option.
- The AST structure for route patterns now includes a `.params` getter on hostname/pathname segments to easily iterate over defined parameters.
- Extra parameters passed to `RoutePattern.href` are now allowed and do not cause a type error, while autocomplete for required parameters is maintained.
- Performance improvements: `ArrayMatcher.match` is ~1.06x faster, and `TrieMatcher.match` is ~1.17x faster.
- `paramsMeta` now correctly shows a nameless wildcard match (`{ type: '*', name: '*' }`) when the hostname is omitted in a pattern.
- `TrieMatcher` now supports storing and matching overlapping routes by storing an array of route patterns in trie nodes.
🐛 Bug Fixes
- When generating `href` for a pattern containing a nameless wildcard outside of an optional segment, `HrefError` now correctly throws with type `nameless-wildcard` instead of the misleading `missing-params` type. Error messages for `HrefError` types have been simplified.
- Patterns with an omitted port now correctly match URLs that have an empty port (`''`) instead of matching any port.
- Specificity ordering when using default matchers is now correct because omitted hostnames are represented as nameless wildcards in `paramsMeta`.