Fix infinite loop in StepBoxGridReview auto-build
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-school (push) Successful in 41s
CI / test-go-edu-search (push) Successful in 35s
CI / test-python-klausur (push) Failing after 2m41s
CI / test-python-agent-core (push) Successful in 37s
CI / test-nodejs-website (push) Successful in 35s

Auto-build was triggering on every grid.zones.length change, which
happens on every rebuild (zone indices increment). Now uses a ref
to ensure auto-build fires only once. Also removed boxZones.length===0
condition that could trigger unnecessary builds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-04-13 17:06:11 +02:00
parent b5900f1aff
commit 48de4d98cd

View File

@@ -1,6 +1,6 @@
'use client'
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useGridEditor } from '@/components/grid-editor/useGridEditor'
import type { GridZone } from '@/components/grid-editor/types'
import { GridTable } from '@/components/grid-editor/GridTable'
@@ -96,15 +96,16 @@ export function StepBoxGridReview({ sessionId, onNext }: StepBoxGridReviewProps)
await buildBoxGrids({ [String(boxIdx)]: layoutType })
}, [buildBoxGrids])
// Auto-build on first load if box zones have no cells
// Auto-build once on first load if box zones have no cells
const autoBuildDone = useRef(false)
useEffect(() => {
if (!grid || loading || building) return
const needsBuild = boxZones.length === 0 || boxZones.some(z => !z.cells || z.cells.length === 0)
// Only auto-build if we know there are boxes (check structure_result via a quick fetch)
if (!grid || loading || building || autoBuildDone.current) return
const needsBuild = boxZones.some(z => !z.cells || z.cells.length === 0)
if (needsBuild && sessionId) {
autoBuildDone.current = true
buildBoxGrids()
}
}, [grid?.zones?.length, loading]) // eslint-disable-line react-hooks/exhaustive-deps
}, [grid, loading]) // eslint-disable-line react-hooks/exhaustive-deps
if (loading) {
return (