Skip to content

feat!: migrate to @msw/url#2678

Open
kettanaito wants to merge 4 commits intomainfrom
fix/use-msw-url
Open

feat!: migrate to @msw/url#2678
kettanaito wants to merge 4 commits intomainfrom
fix/use-msw-url

Conversation

@kettanaito
Copy link
Copy Markdown
Member

@kettanaito kettanaito commented Mar 19, 2026

Breaking change

This is a breaking change. RegExp tokens in string patterns are no longer supported like in path-to-regexp because string patterns don't compile to regexp anymore. This will break some consumers, but I predict the blast radius to be rather small.

Changes

  • Migrates from path-to-regexp to an in-house @msw/url. Path matching is no longer regexp-based but token-based. Better performance, fewer vulnerabilities.
  • Improves path matching performance in certain scenarios (@msw/url is faster than path-to-regexp in most scenarios, in others the performance is roughly the same).
  • Refactors the related functionality in MSW.
  • No breaking changes expected.

Todos

  • Rewrite matchRequestUrl.test.ts. No need to assert what matchPattern does already. Actually test what the function does: handles RegExp, cleans urls, normalizes the path, and 1-2 simple absolute/relative url matches for posterity.
  • Check the params value for matching against RegExp in path-to-regexp. If it returned index-based capturing groups, implement that.

if (pattern instanceof RegExp) {
return {
matches: pattern.test(cleanUrl),
params: {},
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support index-based matching groups as parameters? Not sure if that's how path-to-regexp behaved. Would be nice to match that behavior here.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/msw@2678

commit: b654839

@kettanaito kettanaito changed the title fix: migrate to @msw/url feat!: migrate to @msw/url Mar 20, 2026
@kettanaito kettanaito added the BREAKING CHANGE Pull request introducing breaking changes. label Mar 20, 2026
@kettanaito kettanaito added this to the 3.0 milestone Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BREAKING CHANGE Pull request introducing breaking changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using the wildcard token to try to match random ports doesn't work if preceded by a colon

1 participant