From d062519f604b000fff775b904d18c95a2e0c323b Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 8 Feb 2025 15:48:08 +0800 Subject: [PATCH] fix: use ref not set init value --- web/app/components/base/features/context.tsx | 2 +- .../components/base/file-uploader/store.tsx | 2 +- web/app/components/base/mermaid/index.tsx | 24 +++++++++---------- web/app/components/develop/code.tsx | 4 ++-- .../provider-added-card/cooldown-timer.tsx | 2 +- .../share/text-generation/result/index.tsx | 6 ++--- web/app/components/workflow/context.tsx | 2 +- web/hooks/use-mitt.ts | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/web/app/components/base/features/context.tsx b/web/app/components/base/features/context.tsx index 3c9347c0c5..dc04f6b5d3 100644 --- a/web/app/components/base/features/context.tsx +++ b/web/app/components/base/features/context.tsx @@ -14,7 +14,7 @@ type FeaturesProviderProps = { children: React.ReactNode } & Partial export const FeaturesProvider = ({ children, ...props }: FeaturesProviderProps) => { - const storeRef = useRef() + const storeRef = useRef(undefined) if (!storeRef.current) storeRef.current = createFeaturesStore(props) diff --git a/web/app/components/base/file-uploader/store.tsx b/web/app/components/base/file-uploader/store.tsx index 3ad0b74f05..b5f8d6a50e 100644 --- a/web/app/components/base/file-uploader/store.tsx +++ b/web/app/components/base/file-uploader/store.tsx @@ -54,7 +54,7 @@ export const FileContextProvider = ({ value, onChange, }: FileProviderProps) => { - const storeRef = useRef() + const storeRef = useRef(undefined) if (!storeRef.current) storeRef.current = createFileStore(value, onChange) diff --git a/web/app/components/base/mermaid/index.tsx b/web/app/components/base/mermaid/index.tsx index b86eaec329..c2acbca989 100644 --- a/web/app/components/base/mermaid/index.tsx +++ b/web/app/components/base/mermaid/index.tsx @@ -40,7 +40,7 @@ const Flowchart = ( const prevPrimitiveCode = usePrevious(props.PrimitiveCode) const [isLoading, setIsLoading] = useState(true) - const timeRef = useRef() + const timeRef = useRef(0) const [errMsg, setErrMsg] = useState('') const [imagePreviewUrl, setImagePreviewUrl] = useState('') @@ -119,22 +119,22 @@ const Flowchart = ( { svgCode - &&
setImagePreviewUrl(svgCode)}> - {svgCode && mermaid_chart} -
+ &&
setImagePreviewUrl(svgCode)}> + {svgCode && mermaid_chart} +
} {isLoading - &&
- -
+ &&
+ +
} { errMsg - &&
- -   - {errMsg} -
+ &&
+ +   + {errMsg} +
} { imagePreviewUrl && ( setImagePreviewUrl('')} />) diff --git a/web/app/components/develop/code.tsx b/web/app/components/develop/code.tsx index 1c9e2b57f3..513eb7daef 100644 --- a/web/app/components/develop/code.tsx +++ b/web/app/components/develop/code.tsx @@ -204,8 +204,8 @@ function CodeGroupPanels({ children, targetCode, ...props }: ICodeGroupPanelsPro } function usePreventLayoutShift() { - const positionRef = useRef() - const rafRef = useRef() + const positionRef = useRef(undefined) + const rafRef = useRef(undefined) useEffect(() => { return () => { diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/cooldown-timer.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/cooldown-timer.tsx index a21483c29f..a59e336664 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/cooldown-timer.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/cooldown-timer.tsx @@ -19,7 +19,7 @@ const CooldownTimer = ({ secondsRemaining, onFinish }: CooldownTimerProps) => { [currentTime], ) - const countdownTimeout = useRef(undefined) + const countdownTimeout = useRef(undefined) const clearCountdown = useCallback(() => { if (countdownTimeout.current) { window.clearTimeout(countdownTimeout.current) diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index 6d5c63273a..4bea3cca91 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -24,7 +24,7 @@ import { getFilesInLogs, } from '@/app/components/base/file-uploader/utils' -export interface IResultProps { +export type IResultProps = { isWorkflow: boolean isCallBatchAPI: boolean isPC: boolean @@ -80,14 +80,14 @@ const Result: FC = ({ }, [controlStopResponding]) const [completionRes, doSetCompletionRes] = useState('') - const completionResRef = useRef() + const completionResRef = useRef(undefined) const setCompletionRes = (res: any) => { completionResRef.current = res doSetCompletionRes(res) } const getCompletionRes = () => completionResRef.current const [workflowProcessData, doSetWorkflowProcessData] = useState() - const workflowProcessDataRef = useRef() + const workflowProcessDataRef = useRef(undefined) const setWorkflowProcessData = (data: WorkflowProcess) => { workflowProcessDataRef.current = data doSetWorkflowProcessData(data) diff --git a/web/app/components/workflow/context.tsx b/web/app/components/workflow/context.tsx index 77c8291389..bb34ce6319 100644 --- a/web/app/components/workflow/context.tsx +++ b/web/app/components/workflow/context.tsx @@ -11,7 +11,7 @@ type WorkflowProviderProps = { children: React.ReactNode } export const WorkflowContextProvider = ({ children }: WorkflowProviderProps) => { - const storeRef = useRef() + const storeRef = useRef(undefined) if (!storeRef.current) storeRef.current = createWorkflowStore() diff --git a/web/hooks/use-mitt.ts b/web/hooks/use-mitt.ts index b9094bc262..9aea988b6e 100644 --- a/web/hooks/use-mitt.ts +++ b/web/hooks/use-mitt.ts @@ -43,7 +43,7 @@ const defaultSubcribeOption: UseSubcribeOption = { function useMitt( mitt?: Emitter, ): UseMittReturn { - const emitterRef = useRef>() + const emitterRef = useRef | undefined>(undefined) if (!emitterRef.current) emitterRef.current = mitt ?? create()