mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -69,10 +69,9 @@ export function PipelineBuilder({
|
|||||||
|
|
||||||
// Keep a ref to steps so callbacks always read the latest value
|
// Keep a ref to steps so callbacks always read the latest value
|
||||||
// without needing steps in their dependency arrays (prevents stale closures).
|
// 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);
|
const stepsRef = useRef(steps);
|
||||||
useEffect(() => {
|
stepsRef.current = steps;
|
||||||
stepsRef.current = steps;
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
apiGet<{ settings: Record<string, string> }>("/v1/settings")
|
apiGet<{ settings: Record<string, string> }>("/v1/settings")
|
||||||
|
|||||||
Reference in New Issue
Block a user