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-43 — useEffect 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
Split from #27 (item 5 of 6).
Problem
EditionSelectionrenders a "Redirecting to current edition…" state and then navigates viauseEffectwhen a festival has exactly one edition, causing a flash before redirect.Verified:
src/pages/EditionSelection.tsx:24-43—useEffectredirect wheneditionListQuery.data?.length === 1src/pages/EditionSelection.tsx:61-73— the "Redirecting…" render statesrc/routes/festivals/$festivalSlug/index.tsx— route has nobeforeLoad/loader.Fix
Move the redirect into the route's
beforeLoadso the component never renders when redirecting:Then remove the
useEffectredirect and the "Redirecting…" state fromEditionSelection.tsx. Use the existing editions query-options factory (src/api/editions/…);beforeLoadhere hasparams.festivalSlug(the query currently keys offfestival.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
Files
src/routes/festivals/$festivalSlug/index.tsxsrc/pages/EditionSelection.tsx