Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3: regexparam-based route patterns #337

Merged
merged 18 commits into from
Sep 14, 2023
Merged

V3: regexparam-based route patterns #337

merged 18 commits into from
Sep 14, 2023

Conversation

molefrog
Copy link
Owner

@molefrog molefrog commented Sep 13, 2023

Removes default matcher and replaces it with regexparam

Breaking changes

Matching

  • no plus sign modifiers "/:user+"
  • no named wildcards "/:user*"
  • no optional wildcards "/*?" (yet! see Optional wildcards lukeed/regexparam#25)
  • "/users/:id-:name" doesn't work. But, this is supported by path-to-regexp
  • when pattern ends with a trailing slash, it matches both "/home/" and "/home", but I suppose it is a better DX
  • router no longer accepts matcher prop. Instead, there is a parser prop that allows to customize pattern parsing. Now it is easier to integrate with path-to-regexp

Base paths

  • Routes can no longer refer to absolute paths (e.g. ~/home). Why? Because when you are inside a nested context, the content won't be rendered anyway and it requires additional work to support it in regexparam

Modules

  • wouter/matcher has been removed

TODO

  • TypeScript types
  • Type specs for useRoute

Further improvements

  1. Memoize constructed patterns: don't parse the string when pattern doesn't change
  2. useRoute should not work with falsey patterns, while Route should always render when pattern isn't provided

@github-actions
Copy link

github-actions bot commented Sep 13, 2023

size-limit report 📦

Path Size
packages/wouter/esm/index.js 1.39 KB (-9.69% 🔽)
packages/wouter/esm/use-location.js 664 B (0%)
packages/wouter-preact/esm/index.js 915 B (-14.25% 🔽)
packages/wouter-preact/esm/use-location.js 200 B (0%)

@molefrog
Copy link
Owner Author

@jeetiss Hi, here are the things I need your help with:

  • Review the PR. Did I miss anything?
  • Make vitest ignore old type tests and drop lint-types command in favour of test-types

Copy link
Collaborator

@jeetiss jeetiss left a comment

Choose a reason for hiding this comment

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

I dropped the cache and almost all tests work now, could you fix last one in wouter-preact package

<Route path="/:anything*">Nothing was found!</Route>

(as I understand named wildcard params doesn't supported by parser)

i think it is better to disable tests for types now (or merge with red ci) and i going to try to fix them in separate PR

@molefrog
Copy link
Owner Author

i think it is better to disable tests for types now (or merge with red ci) and i going to try to fix them in separate PR

This test does work for me, how do I clean the cache?

@molefrog
Copy link
Owner Author

I figured it out! The test has been fixed.

@molefrog
Copy link
Owner Author

Apparently, there was no actual task for linting types on CI 😄

@molefrog molefrog merged commit 6652ab8 into v3 Sep 14, 2023
2 checks passed
@molefrog molefrog deleted the feat/regexparam branch September 14, 2023 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants