From c21c73b831231103a1729694e4c3fce3e0ff89f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Tue, 3 Dec 2024 14:27:45 +0100 Subject: [PATCH] fix: adjust id retrieval for autoRefresh https://github.com/gisce/webclient/issues/1415 --- src/widgets/views/Form.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/widgets/views/Form.tsx b/src/widgets/views/Form.tsx index 588670f3..515c114b 100644 --- a/src/widgets/views/Form.tsx +++ b/src/widgets/views/Form.tsx @@ -6,6 +6,7 @@ import { useRef, useContext, useCallback, + useMemo, } from "react"; import { Form as FormOoui, parseContext } from "@gisce/ooui"; import { @@ -253,6 +254,18 @@ function Form(props: FormProps, ref: any) { const getCurrentId = useCallback(() => { return id || createdId.current; }, [id]); + const [refId, setRefId] = useState(() => createdId.current); + + useEffect(() => { + if (createdId.current !== refId) { + setRefId(createdId.current); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [createdId.current]); + + const currentId = useMemo(() => { + return id || refId; + }, [id, refId]); function getFields() { return fields; @@ -1087,7 +1100,7 @@ function Form(props: FormProps, ref: any) { const { pause, resume } = useAutorefreshableFields({ model, - id, + id: currentId, context: parentContext, autorefreshableFields: formOoui?.autorefreshableFields, fieldDefs: fields,