route-pattern@0.20.0
Breaking Changes๐ฆ remixView on GitHub โ
โ 3 breakingโจ 3 features๐ 2 fixes๐ง 6 symbols
Summary
This release brings significant consistency improvements to RoutePattern search parameter handling by aligning with URLSearchParams standards, which results in breaking changes regarding key-only search constraints. Additionally, pathname parameter matching now returns decoded values, and internal matching performance has been optimized.
โ ๏ธ Breaking Changes
- RoutePattern search param pattern decoding and serialization is now consistent with URLSearchParams. This means that previously distinct constraints like `?q` (key only) and `?q=` (key and value) are now semantically equivalent and serialize identically. RoutePatterns can no longer represent a "key and any value" constraint.
- RoutePattern.ast is now typed as deeply readonly. Direct mutation of properties on pattern.ast, its Maps, Sets, or Arrays will result in compile-time errors (e.g., pattern.ast.protocol = 'https' or pattern.ast.search.set(...)).
- The `missing-search-param` error type thrown by `RoutePattern.href` was removed because "key and any value" search constraints were removed.
Migration Steps
- If you relied on RoutePattern distinguishing between a search parameter present without a value (`?q`) and one present with an empty value (`?q=`), update your logic as these are now treated identically.
- If you relied on RoutePattern representing a "key and any value" constraint, you must find an alternative implementation, as this constraint type has been removed.
- If you were mutating properties of `pattern.ast` (e.g., `pattern.ast.search.set(...)`), update your code to create new AST structures or use methods that return new instances instead of mutating the existing readonly structure.
- If you require the percent-encoded version of a matched pathname parameter, use `encodeURI(decodedValue)` on the result of `pattern.match(url)?.params.paramName`.
โจ New Features
- Pathname parameters matched by RoutePattern are now decoded, returning the actual decoded string instead of the percent-encoded version (e.g., '๐ฟ' instead of '%F0%9F%92%BF').
- TrieMatcher.match performance improved from O(mยทlog(m)) to O(m) by avoiding sorting of matches.
- Type inference speed improved for RoutePattern.href, RoutePattern.match, and Params, potentially resolving TS2589 errors related to excessively deep type instantiation.
๐ Bug Fixes
- Search param patterns are now parsed according to the WHATWG application/x-www-form-urlencoded parsing spec, correctly decoding characters like '+' to ' ' in values.
- Search param serialization is consistent with URLSearchParams; for example, `new RoutePattern('?q=').search` now correctly yields 'q=' instead of 'q'.