Skip to content

watchlist-mood-page: runtime guard for moodId param (throw notFound) #515

@electather

Description

@electather

Part of epic #491. Review nit (B3) on apps/client/src/features/watchlist/components/watchlist-mood-page.tsx:23.

Problem

strict: false on useParams skips route-schema validation. TS cast succeeds at compile time regardless of actual URL. Stale bookmark to /watchlist/moods/unknown-id or renamed mood → passes string not in MOOD_IDS directly to fetchMoodItems → server's moodParamSchema returns 400 → user sees generic error fallback instead of 404.

Fix options

A — runtime guard:

const rawId = useParams({ strict: false });
const moodId = (rawId as { moodId?: string }).moodId as MoodId;
if (!MOOD_IDS.includes(moodId as MoodId)) {
  throw notFound();
}

B — declare params: moodParamSchema on the route file and use strict: true here; router enforces before component renders. Preferred if pairs with route-loader migration (#issue-22).

Acceptance criteria

  • Invalid moodId routes to 404, not generic error fallback.
  • Regression test: unknown moodId in URL → 404 component renders.
  • vp check + vp test pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumNormal priorityscope: client@ent-mcp/client packagetype: bugSomething is broken or behaving unexpectedly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions