Skip to content

feat(detection): add alternatePackageNames so React Router v6 is detected - #1001

Open
Ref34t wants to merge 1 commit into
PostHog:mainfrom
Ref34t:feat/react-router-v6-detection
Open

feat(detection): add alternatePackageNames so React Router v6 is detected#1001
Ref34t wants to merge 1 commit into
PostHog:mainfrom
Ref34t:feat/react-router-v6-detection

Conversation

@Ref34t

@Ref34t Ref34t commented Jul 28, 2026

Copy link
Copy Markdown

Why

React Router v6 ships the router as react-router-dom; v7 consolidated onto react-router. The detection gate only checked the v7 name:

return packageJson ? hasDeclaredDependency('react-router', packageJson) : false;

hasDeclaredDependency is an exact key lookup, so a v6 project — which declares only react-router-dom — never matched, and first-match detection carried it through to the javascript_web fallback.

The rest of the config already assumes v6 is supported: minimumVersion is '6.0.0', and getReactRouterMode in ./utils checks both package names and has an explicit V6 branch. Neither is reachable, because detection fails first. context-mill's dedicated react-react-router-6 skill variant is unreachable for the same reason, so a v6 project gets the generic javascript_web rules — whose pageview guidance is written for "SPAs without a framework router".

What this adds

An optional alternatePackageNames on FrameworkDetection, rather than special-casing React Router in the runner — following the guidance in .claude/skills/wizard-development: "the interface is missing a field — extend the interface, don't add special-case logic to the runner."

React Router declares ['react-router-dom'] there, and both names are now used in detect, getVersion, getInstalledVersion, and the is-it-installed warning in posthog-integration.

Test plan

  • Two new cases in src/lib/detection/__tests__/framework.test.ts: a v6 project (react-router-dom only) and a v7 project both resolve to Integration.reactRouter.
  • pnpm build && vitest run — 1558 tests pass across 113 files.
  • tsc --noEmit — 27 pre-existing errors before and after, none in the touched files.
  • Ran every framework's detect() predicate over each app in context-mill/example-apps: react-react-router-6 resolved to javascript_web before and react-router after. react-react-router-7-data, -declarative and -framework are unchanged, and no other app's result moved.

…cted

React Router v6 ships the router as `react-router-dom`; v7 consolidated
onto `react-router`. The detection gate only checked `react-router`, so v6
projects declared only as `react-router-dom` never matched and fell
through to the javascript_web fallback.

The rest of the config already assumes v6 works: `minimumVersion` is
'6.0.0' and `getReactRouterMode` has an explicit V6 branch, but neither
was reachable because detection ran first. context-mill's dedicated
`react-react-router-6` skill variant was unreachable for the same reason.

Adds an optional `alternatePackageNames` to FrameworkDetection rather than
special-casing react-router in the runner, and uses both names in detect,
getVersion, getInstalledVersion, and the is-it-installed warning.

Verified against context-mill's example apps by running every framework
predicate over each one: react-react-router-6 resolved to javascript_web
before and react-router after, with the three v7 variants unchanged.
@Ref34t
Ref34t requested a review from a team as a code owner July 28, 2026 13:52
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.

1 participant