router icon indicating copy to clipboard operation
router copied to clipboard

Custom Route Resolvers

Open posva opened this issue 1 year ago • 3 comments

New version of the internal matcher (renamed as resolver). With more responsibilities and allowing it to be overridden:

  • custom parsing /serializing of params (numbers, dates, classes, etc)
  • matching on the query

posva avatar Dec 05 '24 10:12 posva

Deploy Preview for vue-router canceled.

Name Link
Latest commit 6481cf636eb1c50fe7b750323bca3e1d9b5d863e
Latest deploy log https://app.netlify.com/projects/vue-router/deploys/68cc24d3c61db8000803ac2d

netlify[bot] avatar Dec 05 '24 10:12 netlify[bot]

Open in StackBlitz

npm i https://pkg.pr.new/vue-router@2415

commit: 6481cf6

pkg-pr-new[bot] avatar Dec 05 '24 10:12 pkg-pr-new[bot]

Codecov Report

:x: Patch coverage is 77.08688% with 269 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 89.61%. Comparing base (6a11243) to head (6481cf6). :warning: Report is 196 commits behind head on main.

Files with missing lines Patch % Lines
packages/router/src/experimental/router.ts 61.22% 226 Missing and 2 partials :warning:
.../src/experimental/route-resolver/resolver-fixed.ts 86.52% 19 Missing :warning:
...imental/route-resolver/matchers/matcher-pattern.ts 92.10% 9 Missing :warning:
...tal/route-resolver/matchers/param-parsers/index.ts 75.00% 8 Missing :warning:
...l/route-resolver/matchers/matcher-pattern-query.ts 93.24% 5 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2415      +/-   ##
==========================================
- Coverage   94.90%   89.61%   -5.29%     
==========================================
  Files          34       46      +12     
  Lines        3002     4103    +1101     
  Branches      846     1090     +244     
==========================================
+ Hits         2849     3677     +828     
- Misses        150      421     +271     
- Partials        3        5       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 06 '24 09:12 codecov[bot]

[!CAUTION]

Review failed

The pull request is closed.

Walkthrough

Adds an experimental resolver-driven router (matchers, param parsers, FixedResolver, experimental_createRouter), an experiments-playground app that uses it, many tests and typings, docs/typedoc adjustments, packaging/tooling updates (tsdown/tsup, exports), URL/encoding/query refinements, and assorted CI/gitignore changes.

Changes

Cohort / File(s) Summary
Repo ignores & attributes
/.gitignore, /.gitattributes, /.git-crypt/.gitattributes, packages/router/.gitignore, packages/docs/.gitignore, packages/experiments-playground/.gitignore
Add/remove ignore rules and git-crypt attributes; ignore temp/config, docs api output, package artifacts and workspace-specific files.
Root manifest & tooling
/package.json
Update packageManager and Volta node versions; bump devDependencies and add pnpm.onlyBuiltDependencies.
Docs & TypeDoc
packages/docs/.vitepress/config/en.ts, packages/docs/.vitepress/config/zh.ts, packages/docs/run-typedoc.mjs, packages/docs/typedoc-markdown.mjs, packages/docs/package.json, packages/docs/typedoc.tsconfig.json
Switch API sidebar to typedoc JSON, change TypeDoc options/plugins and output formatting, add theme dependency, and extend tsconfig types for docs.
Experiments playground (new package)
packages/experiments-playground/* (package.json, vite.config.ts, tsconfig.*, src/**, index.html, .vscode/extensions.json, README.md)
Add a Vite+Vue experimental playground with router wiring, example pages/components, TS/Vite configs, aliases to local router source, scripts, and editor recommendations.
Router packaging & publish layout
packages/router/package.json, packages/router/tsdown.config.ts, packages/router/vue-router.node.mjs, packages/router/rollup.config.mjs (deleted), packages/router/tsconfig.json, packages/router/test-dts/index.d.ts, packages/router/size-checks/*, scripts/check-size.mjs
Migrate build tooling toward tsdown/tsup, adjust published exports and declaration outputs (including root vue-router.node.mjs), remove old Rollup config, update size-check targets and published file list.
Experimental router implementation
packages/router/src/experimental/**/*
Add resolver base, FixedResolver, matcher-pattern implementations (static/dynamic/star/hash/query), param-parsers (ints/bools/strings/defaults), MatchMiss error, resolver utilities, experimental_createRouter, merge helpers, and public re-exports.
Experimental matcher & parser tests
`packages/router/src/experimental/**/(*.spec.ts
*.test-d.ts), packages/router/src/experimental/route-resolver/matchers/test-utils.ts`
Core router refactors & API shifts
packages/router/src/router.ts, packages/router/src/index.ts, packages/router/src/scrollBehavior.ts, packages/router/src/navigationGuards.ts, packages/router/src/errors.ts
Delegate much router surface to experimental/base contracts, move RouterScrollBehavior to its own module, add extractChangingRecords and typed error listener, adjust redirect/readiness handling and Vue type augmentation placement.
URL, encoding and query changes
packages/router/src/location.ts, packages/router/src/encoding.ts, packages/router/src/query.ts
Export LocationNormalized.query, add NEW_stringifyURL, refine parseURL semantics (search/hash handling, keep leading '?'), export SLASH_RE/commonEncode, expand encode/decode to accept null/undefined, and allow stringifyQuery(undefined).
Matcher utilities & ranking
packages/router/src/matcher/*, packages/router/src/matcher/pathParserRanker.ts
Introduce PATH_PARSER_OPTIONS_DEFAULTS, narrow comparePathParserScore inputs, import/export mergeOptions utility, add pickParams helper, and export normalizeRecordProps/checkChildMissingNameWithEmptyPath.
Types & utils
packages/router/src/types/*, packages/router/src/utils/index.ts, packages/router/src/global.d.ts, packages/router/src/typed-routes/*
Add utility types (IsNull, IsUnknown, Awaitable, Simplify), refine type guards, add identityFn and exported mergeOptions, remove some global var declarations, and extend redirect signature to include from.
Devtools/logging
packages/router/src/devtools.ts
Replace direct console.warn with the internal warn helper.
Tests & vitest config updates
packages/router/__tests__/*.ts, packages/router/vitest.config.ts
Update tests for return-based navigation guard API (remove next callbacks), fix parseQuery expectations, and add coverage excludes for experimental files.
Playground & docs dependency bumps
packages/playground/package.json, packages/docs/package.json
Bump Vue/Vite and docs dependencies and add typedoc-vitepress-theme.
CI workflow
.github/workflows/test.yml, .github/workflows/pkg.pr.new.yml
Upgrade actions/checkout to v5 and remove/streamline DTS build steps in workflows.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant App as Vue App
  participant Router as experimental_createRouter
  participant Resolver as FixedResolver
  participant History as RouterHistory
  participant Guards as Guards

  User->>App: user click / programmatic navigation
  App->>Router: router.push(to)
  Router->>Resolver: resolve(to, currentLocation)
  Resolver-->>Router: { name, path, params, query, hash, matched }
  Router->>Guards: run global & per-route guards (return-based)
  alt allowed
    Router->>History: apply navigation (push/replace)
    Router-->>App: update currentRoute
  else cancelled/redirected
    Router-->>App: NavigationFailure / redirect
  end
sequenceDiagram
  autonumber
  participant Resolver as FixedResolver
  participant Path as PathMatchers
  participant Query as QueryMatchers
  participant Parsers as ParamParsers

  Resolver->>Path: path.match(pathname)
  Path-->>Resolver: path params or miss()
  Resolver->>Query: run query matchers -> match(query)
  Query->>Parsers: parse values (int / bool / string / defaults)
  Parsers-->>Query: typed values
  Query-->>Resolver: merged params (path + query + hash)
  Resolver-->>Resolver: assemble matched chain and final location

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~150 minutes

Possibly related PRs

  • vuejs/router#2415 — Implements the experimental resolver/matcher system (matchers, param-parsers, resolver-fixed, experimental_createRouter, tests, typings); strongly related and likely overlapping.

Poem

A rabbit taps routes on the midnight screen,
Matchers hum softly; parsers tidy the sheen.
A fixed resolver hops through path and query,
Docs bloom maps, a playground winks—so merry.
Hooray, new routes! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.38% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed "Custom Route Resolvers" succinctly and accurately describes the main change: introducing a new, overridable resolver/matcher system that enables custom parsing/serializing of route params and query-based matching. The title is concise, specific to the feature, and contains no noisy details or file lists. A reviewer scanning PR history would understand this PR introduces custom route resolution capabilities.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2938bff7622c0c487f15a41f8924788087dd936a and 6481cf636eb1c50fe7b750323bca3e1d9b5d863e.

📒 Files selected for processing (8)
  • .github/workflows/pkg.pr.new.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • package.json (3 hunks)
  • packages/router/api-extractor.json (0 hunks)
  • packages/router/package.json (6 hunks)
  • packages/router/src/globalExtensions.ts (0 hunks)
  • packages/router/src/index.ts (3 hunks)
  • scripts/release.mjs (0 hunks)
🔥 Files not summarized due to errors (4)
  • .github/workflows/pkg.pr.new.yml: Error: Server error: no LLM provider could handle the message
  • packages/router/package.json: Error: Server error: no LLM provider could handle the message
  • .github/workflows/test.yml: Error: Server error: no LLM provider could handle the message
  • package.json: Error: Server error: no LLM provider could handle the message

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Aug 07 '25 19:08 coderabbitai[bot]