fix: cookie-write uit Server Component (Next.js 16 verbiedt dit)
setActiveSprintCookie werd direct aangeroepen in app/(app)/products/[id]/sprint/[sprintId]/page.tsx,
wat in Next.js 16 een runtime-error oplevert ('Cookies can only be modified in a Server Action
or Route Handler'). Vervangen door een client-side bridge die syncActiveSprintCookieAction
aanroept na mount, zodat de active-sprint cookie nog steeds gesynced blijft met de URL.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1a5c0b2d01
commit
b4aa5d9949
3 changed files with 39 additions and 3 deletions
|
|
@ -40,3 +40,24 @@ export async function setActiveSprintAction(productId: string, sprintId: string)
|
|||
revalidatePath('/', 'layout')
|
||||
return { success: true, sprintId: parsed.data.sprintId }
|
||||
}
|
||||
|
||||
export async function syncActiveSprintCookieAction(productId: string, sprintId: string) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return
|
||||
if (session.isDemo) return
|
||||
|
||||
const parsed = setSchema.safeParse({ productId, sprintId })
|
||||
if (!parsed.success) return
|
||||
|
||||
const sprint = await prisma.sprint.findFirst({
|
||||
where: {
|
||||
id: parsed.data.sprintId,
|
||||
product_id: parsed.data.productId,
|
||||
product: productAccessFilter(session.userId),
|
||||
},
|
||||
select: { id: true },
|
||||
})
|
||||
if (!sprint) return
|
||||
|
||||
await setActiveSprintCookie(parsed.data.productId, parsed.data.sprintId)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import { getSession } from '@/lib/auth'
|
|||
import { getAccessibleProduct } from '@/lib/product-access'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { pbiStatusToApi } from '@/lib/task-status'
|
||||
import { setActiveSprintCookie } from '@/lib/active-sprint'
|
||||
import { SprintBoardClient } from '@/components/sprint/sprint-board-client'
|
||||
import { SyncActiveSprintCookie } from '@/components/sprint/sync-active-sprint-cookie'
|
||||
import { SprintHeader } from '@/components/sprint/sprint-header'
|
||||
import { SprintRunControls } from '@/components/sprint/sprint-run-controls'
|
||||
import { parsePauseContext } from '@/lib/pause-context'
|
||||
|
|
@ -48,8 +48,6 @@ export default async function SprintBoardPage({ params, searchParams }: Props) {
|
|||
})
|
||||
if (!sprint) notFound()
|
||||
|
||||
await setActiveSprintCookie(id, sprint.id)
|
||||
|
||||
const activeSprintRun = await prisma.sprintRun.findFirst({
|
||||
where: {
|
||||
sprint_id: sprint.id,
|
||||
|
|
@ -158,6 +156,7 @@ export default async function SprintBoardPage({ params, searchParams }: Props) {
|
|||
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
<SyncActiveSprintCookie productId={id} sprintId={sprint.id} />
|
||||
<SprintHeader
|
||||
productId={id}
|
||||
productName={product.name}
|
||||
|
|
|
|||
16
components/sprint/sync-active-sprint-cookie.tsx
Normal file
16
components/sprint/sync-active-sprint-cookie.tsx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { syncActiveSprintCookieAction } from '@/actions/active-sprint'
|
||||
|
||||
interface Props {
|
||||
productId: string
|
||||
sprintId: string
|
||||
}
|
||||
|
||||
export function SyncActiveSprintCookie({ productId, sprintId }: Props) {
|
||||
useEffect(() => {
|
||||
syncActiveSprintCookieAction(productId, sprintId)
|
||||
}, [productId, sprintId])
|
||||
return null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue