From dcd5302a2650b17581dd53df6ab873a2f83cc0c3 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 10 Jun 2023 00:42:26 +0200 Subject: [PATCH] Fix/source mangas white screen when directly open page via url (#362) * Correctly handle missing location state In case the view gets opened directly via url, there won't be any location state. This leads to a TypeError when trying to get "contentType" from the location state. Issue was introduced with 4e8813b526fab197a61e22d9a855514f1f9bd203 where the function was adapted incorrectly with code that will never work (good job me KEKW) * Add info about dev mode + strict mode issue --- src/screens/SearchAll.tsx | 3 +++ src/screens/SourceMangas.tsx | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/screens/SearchAll.tsx b/src/screens/SearchAll.tsx index 89e265e6..c2a8fe91 100644 --- a/src/screens/SearchAll.tsx +++ b/src/screens/SearchAll.tsx @@ -123,6 +123,9 @@ const SourceSearchPreview = React.memo( useEffect( () => () => { + // INFO: + // with strict mode + dev mode the first request will be aborted. due to using SWR there won't be an + // immediate second request since it's the same key. instead the "second" request will be the error handling of SWR abortRequest( new Error(`SourceSearchPreview(${source.id}, ${source.displayName}): search string changed`), ); diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index df7c9822..5b8aa83d 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -163,9 +163,10 @@ export default function SourceMangas() { const { sourceId } = useParams<{ sourceId: string }>(); const navigate = useNavigate(); - const { state: { contentType: currentLocationContentType = SourceContentType.POPULAR } = {} } = useLocation<{ - contentType: SourceContentType; - }>(); + const { contentType: currentLocationContentType = SourceContentType.POPULAR } = + useLocation<{ + contentType: SourceContentType; + }>().state ?? {}; const { options } = useLibraryOptionsContext(); const [query] = useQueryParam('query', StringParam); @@ -247,6 +248,9 @@ export default function SourceMangas() { return; } + // INFO: + // with strict mode + dev mode the first request will be aborted. due to using SWR there won't be an + // immediate second request since it's the same key. instead the "second" request will be the error handling of SWR abortRequest(new Error(`SourceMangas(${sourceId}): search string changed`)); }, [searchTerm, contentType],