Fix project detail crash: replace dynamic hooks with single query

The project detail page called useQuery inside .map() to fetch file
requirements per round, violating React's rules of hooks. When
competitionRounds changed from [] to [round1, round2], the hook count
changed, causing React to crash with "Cannot read properties of
undefined (reading 'length')".

Fix: Add listRequirementsByRounds endpoint that accepts multiple
roundIds in one query, replacing the dynamic hook pattern with a
single stable useQuery call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt
2026-02-16 15:30:44 +01:00
parent 65a22e6f19
commit f12c29103c
2 changed files with 20 additions and 7 deletions

View File

@@ -818,6 +818,20 @@ export const fileRouter = router({
})
}),
/**
* List file requirements for multiple rounds in a single query.
* Avoids dynamic hook violations when fetching requirements per-round.
*/
listRequirementsByRounds: protectedProcedure
.input(z.object({ roundIds: z.array(z.string()).max(50) }))
.query(async ({ ctx, input }) => {
if (input.roundIds.length === 0) return []
return ctx.prisma.fileRequirement.findMany({
where: { roundId: { in: input.roundIds } },
orderBy: { sortOrder: 'asc' },
})
}),
/**
* Create a file requirement for a stage (admin only)
*/