From c33e65b0f6172e28749aded53477f4c9e9d84fe3 Mon Sep 17 00:00:00 2001 From: Matthias Meister Date: Fri, 3 Apr 2026 18:02:44 +0200 Subject: [PATCH] fix(tool-ui): remove render-time ref mutation in controllable state --- src/components/tool-ui/shared/use-controllable-state.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/components/tool-ui/shared/use-controllable-state.ts b/src/components/tool-ui/shared/use-controllable-state.ts index 8a9afdc..d003180 100644 --- a/src/components/tool-ui/shared/use-controllable-state.ts +++ b/src/components/tool-ui/shared/use-controllable-state.ts @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useMemo, useRef, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; export type UseControllableStateOptions = { value?: T; @@ -20,17 +20,14 @@ export function useControllableState({ () => (isControlled ? (value as T) : uncontrolled), [isControlled, value, uncontrolled], ); - const currentValueRef = useRef(currentValue); - currentValueRef.current = currentValue; const setValue = useCallback( (next: T | ((prev: T) => T)) => { const resolved = typeof next === "function" - ? (next as (prev: T) => T)(currentValueRef.current) + ? (next as (prev: T) => T)(currentValue) : next; - currentValueRef.current = resolved; if (!isControlled) { setUncontrolled(resolved); } @@ -38,7 +35,7 @@ export function useControllableState({ onChange?.(resolved); return resolved; }, - [isControlled, onChange], + [currentValue, isControlled, onChange], ); const setUncontrolledValue = useCallback((next: T) => {