Files
codegraph/docs
Colby Mchenry a50104c895 fix(react-router): read every table a route-building function returns, and the one behind useMemo (#2672)
The route-table pass (`returnedTable`) took the first `return [` anywhere in
a route-building function's body for its table:

- An early guard's `[]` (`if (!user) return [];`) hid the real table.
- A callback's `[]` did too: devanshthakker15/BANKFORM1's `generateRoutes`
  returns `[]` from a `.forEach` callback before its own table.
- A menu that a helper inside the function returns could be read as routes.
- Of `if (admin) return [ … ]; return [ … ]`, only the first branch was read.

A function that returns another function's table (`return buildRoutes()`)
was not followed, and neither was `useMemo`, which hooks-based routers wrap
their table in.

Now `returnedTables` reads what the function's expression body gives, or
what each of its own `return`s gives (`ownReturns`). It steps over the
bodies of arrows, `function`s and methods written inside it, found by a
brace matcher tolerant of JSX text: in `blockEnd` and `opensString`, a quote
right after a word is an apostrophe. `heldTable` reads parentheses around a
value, and reads `useMemo(() => getRoutes(user), [user])` and
`useMemo(getRoutes, [])` as the function's tables. `tableNamed`,
`exportedTable` and `declaredTable` now return every table they find.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:31:31 +00:00
..