Skip to content

Move EditionSelection single-edition auto-redirect to route beforeLoad #84

Description

@chiptus

This was generated by AI during triage.

Split from #27 (item 5 of 6).

Problem

EditionSelection renders a "Redirecting to current edition…" state and then navigates via useEffect when a festival has exactly one edition, causing a flash before redirect.

Verified:

  • src/pages/EditionSelection.tsx:24-43useEffect redirect when editionListQuery.data?.length === 1
  • src/pages/EditionSelection.tsx:61-73 — the "Redirecting…" render state
  • src/routes/festivals/$festivalSlug/index.tsx — route has no beforeLoad/loader.

Fix

Move the redirect into the route's beforeLoad so the component never renders when redirecting:

// src/routes/festivals/$festivalSlug/index.tsx
beforeLoad: async ({ params, context }) => {
  const editions = await context.queryClient.ensureQueryData(
    editionsForFestivalQuery(/* festival id/slug */),
  );
  if (editions.length === 1) {
    throw redirect({
      to: "/festivals/$festivalSlug/editions/$editionSlug",
      params: { festivalSlug: params.festivalSlug, editionSlug: editions[0].slug },
    });
  }
},

Then remove the useEffect redirect and the "Redirecting…" state from EditionSelection.tsx. Use the existing editions query-options factory (src/api/editions/…); beforeLoad here has params.festivalSlug (the query currently keys off festival.id — resolve the festival first if the id is required).

Related

Part of the router-loader adoption tracked in #53 (Effort 2). Small and self-contained; can land independently.

Acceptance

  • A festival with exactly one edition redirects with no visible "Redirecting…" flash.
  • Festivals with 0 or 2+ editions render the list as before.

Files

  • src/routes/festivals/$festivalSlug/index.tsx
  • src/pages/EditionSelection.tsx

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions