fix: resolve schedule data staleness in production builds

- Replace window.location.reload() with router.refresh() in ScheduleGenerator, MatchEditor, RecalculateEloButton for proper Next.js cache invalidation
- Add revalidatePath() call after schedule generation in POST handler
- Add ownerId to tournament creation in cucumber tests for proper permission checks
- Assign tournament_admin role via Prisma after user creation in cucumber tests
- Fix TypeScript type annotations in hooks.ts (tournament id map)
- Update page reload to use networkidle in common-steps.ts
- Clear .next/ cache before cucumber tests in justfile
- Add .turbo to clean target
- Add comprehensive debug logging to schedule API route
- Document findings in docs/TROUBLESHOOTING_SCHEDULE_GENERATION.md
This commit is contained in:
2026-05-01 16:39:50 -07:00
parent 9353ab1edc
commit caefb0dcc0
11 changed files with 454 additions and 23 deletions
+4 -2
View File
@@ -1,6 +1,7 @@
"use client"
import { useState } from "react"
import { useRouter } from "next/navigation"
import type { Player, Match } from "@prisma/client"
interface MatchEditorProps {
@@ -40,6 +41,7 @@ export default function MatchEditor({
prefilledP4,
prefilledRound,
}: MatchEditorProps) {
const router = useRouter()
// Check if players are prefilled from URL params
const hasPrefilledPlayers = prefilledP1 && prefilledP2 && prefilledP3 && prefilledP4;
@@ -170,9 +172,9 @@ export default function MatchEditor({
isCasual: false,
})
// Reload the page to show updated matches
// Refresh the page to show updated matches
setTimeout(() => {
window.location.reload()
router.refresh()
}, 1000)
} catch {
setError("An error occurred. Please try again.")
+3 -1
View File
@@ -1,8 +1,10 @@
"use client"
import { useState } from "react"
import { useRouter } from "next/navigation"
export function RecalculateEloButton() {
const router = useRouter()
const [isLoading, setIsLoading] = useState(false)
const handleClick = async () => {
@@ -33,7 +35,7 @@ export function RecalculateEloButton() {
if (data.success) {
alert(`Recalculation completed: ${JSON.stringify(data.data)}`)
window.location.reload()
router.refresh()
} else {
alert(`Error: ${data.error}`)
}
+6 -1
View File
@@ -1,6 +1,7 @@
"use client"
import { useState } from "react"
import { useRouter } from "next/navigation"
interface ScheduleGeneratorProps {
tournamentId: number
@@ -9,6 +10,7 @@ interface ScheduleGeneratorProps {
}
export function ScheduleGenerator({ tournamentId, teamCount, existingRounds }: ScheduleGeneratorProps) {
const router = useRouter()
const [isGenerating, setIsGenerating] = useState(false)
const [error, setError] = useState("")
const [result, setResult] = useState<{
@@ -47,6 +49,9 @@ export function ScheduleGenerator({ tournamentId, teamCount, existingRounds }: S
matchupsCreated: data.matchupsCreated,
})
setIsGenerating(false)
// Re-fetch the schedule data from the server
router.refresh()
} catch {
setError("An error occurred. Please try again.")
setIsGenerating(false)
@@ -81,7 +86,7 @@ export function ScheduleGenerator({ tournamentId, teamCount, existingRounds }: S
return
}
window.location.reload()
router.refresh()
} catch {
setError("An error occurred. Please try again.")
setIsGenerating(false)