From 8d803e450ed7057e3055508de5972187227c2b04 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Wed, 6 Dec 2023 16:29:35 +0100 Subject: [PATCH] fix(modelview): validate prevdata before saving --- src/components/sectionList/listView/useModelListView.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/sectionList/listView/useModelListView.tsx b/src/components/sectionList/listView/useModelListView.tsx index f942fdd7..474eee69 100644 --- a/src/components/sectionList/listView/useModelListView.tsx +++ b/src/components/sectionList/listView/useModelListView.tsx @@ -133,6 +133,7 @@ export const useModelListView = () => { }) // 404 errors are expected when user havent saved any views + // eslint-disable-next-line @typescript-eslint/no-explicit-any if (query.error && (query.error as any).details?.httpStatusCode !== 404) { console.error(query.error) } @@ -163,11 +164,14 @@ export const useMutateModelListViews = () => { // it's exact data as we got from the request const prevData: WrapInResult | undefined = queryClient.getQueryData(valuesQueryKey) - if (!prevData) { + + // need to validate here since we're not using a selector + const validView = modelListViewsSchema.safeParse(prevData?.result) + if (!validView.success) { return {} } - return prevData.result + return validView.data }, [queryClient]) const saveView = useCallback(