Skip to content

feat: treat React Router / Remix route modules as entry points - #697

Open
wkeuppens wants to merge 1 commit into
peteromallet:mainfrom
wkeuppens:feat/react-router-entry-conventions
Open

feat: treat React Router / Remix route modules as entry points#697
wkeuppens wants to merge 1 commit into
peteromallet:mainfrom
wkeuppens:feat/react-router-entry-conventions

Conversation

@wkeuppens

Copy link
Copy Markdown

Problem

Route modules in a file-based router have no importers by design — the framework loads them from the filesystem — so every one is reported as an orphaned file. On a React Router project that is most of the app.

Next.js App Router already has convention handling here. This adds the same for React Router / Remix rather than introducing a second mechanism.

Detection

Prefers a react-router.config.* or remix.config.* file, and falls back to checking package.json for @react-router/* or @remix-run/* — because the framework's own template ships a Vite config rather than a react-router.config file, so the config-file check alone misses most real projects.

Exempted

  • anything beneath an app/routes/ or src/routes/ directory
  • root, entry.client and entry.server beside it

.stem strips only the last suffix, so entry.server.jsx stems to entry.server, which is what is matched.

An ordinary module such as app/db.server.js is still reported. A genuinely orphaned file has to stay visible or the detector stops being worth running, so there are explicit negative tests for that and for a file merely named root.js deeper in the tree.

Effect

On a real React Router project (a Shopify app, ~96 JS/JSX files), orphaned findings drop from 49 to 27.

5825 passed, 5 skipped

14 new tests, mirroring the existing TestDetectNextjsProject / TestIsNextjsConventionEntry classes.

Relationship to #696

Independent — different file, and this branches from main. #696 fixes the import graph dropping every edge when file_list is relative. With both applied, orphaned findings on that same project go from 49 to a handful, and the remainder are genuine.

Route modules and framework entry points have no importers by design -- the
file-based router loads them from the filesystem -- so every one of them is
reported as an orphaned file on every project of this shape.

Mirrors the existing Next.js App Router handling rather than adding a new
mechanism: detect the framework at the scan root, then exempt its convention
files.

Detection prefers a react-router.config.* or remix.config.* file and falls back
to checking package.json for @react-router/* or @remix-run/*, because the
framework's own template ships a Vite config rather than a react-router.config.

Exempted: anything beneath an app/routes/ or src/routes/ directory, plus
root, entry.client and entry.server beside it. An ordinary module such as
app/db.server.js is deliberately still reported -- a genuinely orphaned file
has to stay visible, which is what the negative tests cover.

On a real React Router project this drops orphaned findings from 49 to 27.
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