From bdb31137bd2c4490e7fecaa695767c7911cebd91 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 20 Aug 2024 18:00:38 +0800 Subject: [PATCH 1/4] Fix empty edges in useMemo Still need to track downt the root cause of this. --- packages/web/components/templates/library/LibraryContainer.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/web/components/templates/library/LibraryContainer.tsx b/packages/web/components/templates/library/LibraryContainer.tsx index 2a1d72441..6bb4829bd 100644 --- a/packages/web/components/templates/library/LibraryContainer.tsx +++ b/packages/web/components/templates/library/LibraryContainer.tsx @@ -164,6 +164,9 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { const items = itemsPages?.pages .flatMap((ad: LibraryItems) => { + if (!ad.edges) { + return [] + } return ad.edges.map((it) => ({ ...it, isLoading: it.node.state === 'PROCESSING', From d672fe1b44a9cff790e04917857b104922f30804 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 20 Aug 2024 18:14:24 +0800 Subject: [PATCH 2/4] Clear async storage on error --- packages/web/pages/_error.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/web/pages/_error.tsx b/packages/web/pages/_error.tsx index 3331b2300..8cdb78393 100644 --- a/packages/web/pages/_error.tsx +++ b/packages/web/pages/_error.tsx @@ -2,8 +2,15 @@ import NextErrorComponent from 'next/error' import * as Sentry from '@sentry/nextjs' +import { useEffect } from 'react' +import AsyncStorage from '@react-native-async-storage/async-storage' const MyError = ({ statusCode, hasGetInitialPropsRun, err }: any) => { + useEffect(() => { + console.log('unhandled exception occurred, clearing cached data.') + AsyncStorage.clear() + }, []) + if (!hasGetInitialPropsRun && err) { // getInitialProps is not called in case of // https://github.com/vercel/next.js/issues/8592. As a workaround, we pass From 6cb14f3ed320bdc65429d2bde719e1cb7b2d68fe Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 20 Aug 2024 18:17:27 +0800 Subject: [PATCH 3/4] Clear the queryClient on error --- packages/web/pages/_error.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web/pages/_error.tsx b/packages/web/pages/_error.tsx index 8cdb78393..967af76a8 100644 --- a/packages/web/pages/_error.tsx +++ b/packages/web/pages/_error.tsx @@ -3,12 +3,13 @@ import NextErrorComponent from 'next/error' import * as Sentry from '@sentry/nextjs' import { useEffect } from 'react' -import AsyncStorage from '@react-native-async-storage/async-storage' +import { useQueryClient } from '@tanstack/react-query' const MyError = ({ statusCode, hasGetInitialPropsRun, err }: any) => { + const queryClient = useQueryClient() useEffect(() => { console.log('unhandled exception occurred, clearing cached data.') - AsyncStorage.clear() + queryClient.clear() }, []) if (!hasGetInitialPropsRun && err) { From 6d21730fb95291febddc85fe48674daa59ee69f1 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 20 Aug 2024 18:27:39 +0800 Subject: [PATCH 4/4] Better error handling for search --- .../web/lib/networking/library_items/useLibraryItems.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/web/lib/networking/library_items/useLibraryItems.tsx b/packages/web/lib/networking/library_items/useLibraryItems.tsx index 73899f857..c50f79eee 100644 --- a/packages/web/lib/networking/library_items/useLibraryItems.tsx +++ b/packages/web/lib/networking/library_items/useLibraryItems.tsx @@ -277,6 +277,9 @@ export function useGetLibraryItems( query: fullQuery, includeContent: false, })) as LibraryItemsData + if (response.search.errorCodes?.length) { + throw new Error(response.search.errorCodes[0]) + } let wasUnchanged = false if (cached && cached.pageParams.indexOf(pageParam) > -1) { const idx = cached.pageParams.indexOf(pageParam) @@ -326,8 +329,6 @@ export function useGetLibraryItems( return true }) ) - console.log('setting filteredPages: ', filteredPages) - return { ...data, pages: filteredPages,