Skip to content

Move FestivalSelection single-festival auto-redirect to route beforeLoad #85

Description

@chiptus

This was generated by AI during triage.

Split from #27 (item 6 of 6).

Problem

FestivalSelection renders content and then redirects via useEffect when there is exactly one festival, causing a flash before redirect. The subdomain-redirect logic is also duplicated between the effect (handleFestivalClick) and FestivalCard.handleClick.

Verified:

  • src/pages/FestivalSelection.tsx:37-41useEffect calls handleFestivalClick when availableFestivals.length === 1 (note: handleFestivalClick not in deps)
  • src/pages/FestivalSelection.tsx:26-35 / 104-112 — duplicated subdomain logic
  • src/routes/index.tsx — route has no beforeLoad/loader.

Fix

Move the single-festival redirect into the route beforeLoad (fetch festivals via ensureQueryData, throw redirect when exactly one). Keep FestivalCard.handleClick for user-initiated clicks. Remove the useEffect from FestivalSelection.tsx.

⚠️ Subdomain caveat: the effect currently redirects to a subdomain URL (createFestivalSubdomainUrl) via window.location.href when on the main domain, and only uses the in-app path off-main. A router throw redirect can only do in-app navigation, not a cross-origin subdomain jump. Decide how the single-festival case should behave on the main domain — if a subdomain redirect is required there, that part can't move into beforeLoad and should stay a window.location redirect (ideally hoisted out of render). Confirm before implementing.

Related

Part of the router-loader adoption tracked in #53 (Effort 2).

Acceptance

  • Single festival: redirect happens with no visible flash of the selection grid (subdomain behavior preserved per the decision above).
  • 0 or 2+ festivals: selection grid renders as before.

Files

  • src/routes/index.tsx
  • src/pages/FestivalSelection.tsx

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions