fix: sync stepsRef during render, not useEffect

Child component effects (Controls onChange) fire before the parent's
useEffect that synced stepsRef. This caused updateStepSettings to read
stepsRef.current as [] and wipe out newly added steps.

Fix: assign stepsRef.current = steps directly during render so the
ref is always current before any child effects execute.
This commit is contained in:
Siddharth Kumar Sah
2026-03-28 17:02:24 +08:00
parent 04d412873d
commit 748ac607bc
@@ -69,10 +69,9 @@ export function PipelineBuilder({
// Keep a ref to steps so callbacks always read the latest value
// without needing steps in their dependency arrays (prevents stale closures).
// Assigned during render (not useEffect) so it's current before child effects fire.
const stepsRef = useRef(steps);
useEffect(() => {
stepsRef.current = steps;
});
stepsRef.current = steps;
useEffect(() => {
apiGet<{ settings: Record<string, string> }>("/v1/settings")