From 3ee1a5729df464f3fc201496428f8dad1c98a449 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Thu, 2 Oct 2025 18:46:33 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20sync=20FileUploader=20context?= =?UTF-8?q?=20with=20props=20to=20fix=20inconsistent=20file=20parameter=20?= =?UTF-8?q?state=20in=20=E2=80=9CView=20cached=20variables=E2=80=9D."=20(#?= =?UTF-8?q?26548)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/base/file-uploader/store.tsx | 31 ++----------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/web/app/components/base/file-uploader/store.tsx b/web/app/components/base/file-uploader/store.tsx index 7f7cfd5693..cddfdf6f27 100644 --- a/web/app/components/base/file-uploader/store.tsx +++ b/web/app/components/base/file-uploader/store.tsx @@ -1,7 +1,6 @@ import { createContext, useContext, - useEffect, useRef, } from 'react' import { @@ -19,11 +18,13 @@ type Shape = { export const createFileStore = ( value: FileEntity[] = [], + onChange?: (files: FileEntity[]) => void, ) => { return create(set => ({ files: value ? [...value] : [], setFiles: (files) => { set({ files }) + onChange?.(files) }, })) } @@ -54,35 +55,9 @@ export const FileContextProvider = ({ onChange, }: FileProviderProps) => { const storeRef = useRef(undefined) - const onChangeRef = useRef(onChange) - const isSyncingRef = useRef(false) if (!storeRef.current) - storeRef.current = createFileStore(value) - - // keep latest onChange - useEffect(() => { - onChangeRef.current = onChange - }, [onChange]) - - // subscribe to store changes and call latest onChange - useEffect(() => { - const store = storeRef.current! - const unsubscribe = store.subscribe((state: Shape) => { - if (isSyncingRef.current) return - onChangeRef.current?.(state.files) - }) - return unsubscribe - }, []) - - // sync external value into internal store when value changes - useEffect(() => { - const store = storeRef.current! - const nextFiles = value ? [...value] : [] - isSyncingRef.current = true - store.setState({ files: nextFiles }) - isSyncingRef.current = false - }, [value]) + storeRef.current = createFileStore(value, onChange) return (