Skip to content

findNavItem takes a loose string, so a bad id is a boot crash not a type error #136

Description

@OffCrazyFreak

What and where

frontend/src/constants/navigation.ts

export function findNavItem(id: string): INavigationItem {
  const found = ALL_NAV_ITEMS.find((item) => item.id === id) ?? ...;
  if (!found) throw new Error(`Unknown navigation item: ${id}`);
  return found;
}

Called at module scope from bottom-nav-items.ts and products-sheet.tsx.

Current vs expected

Now: the parameter is a loose string, so a typo or a renamed id compiles cleanly and then throws during module evaluation of the root-layout bundle, which takes the whole app down at import rather than degrading.

Expected: an unknown id is a compile error. The id space is a closed, hardcoded set that TypeScript can express.

Why it matters

The blast radius is the entire app, and the failure appears at import time, far from the rename that caused it.

Status and why it is still open

Partly addressed: the lookup now searches every group and their children, so the reachable id space matches the table and productsNavItem resolves. That removes the likeliest cause.

The typing itself is deferred: deriving type NavItemId = (typeof userNavItems)[number]["id"] | ... needs the item arrays converted to as const satisfies readonly INavigationItem[], which changes their inferred type and has to be checked against every consumer that indexes or mutates them. That is wider than a review-fix pass.

How to test

Change one id in a findNavItem("...") call to a string that does not exist. Today tsc passes and the app throws on load; after the fix, tsc should fail.

Trail

  • Review finding 66, reviews/REVIEW-2026-07-26-MOBILE-BOTTOM-NAV-BY-AREA.md
  • Flagged by CodeRabbit, Codex and two Claude reviewers
  • Partly fixed in commit 3b62639 on feat/mobile-bottom-nav

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtCode health and maintainability

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions