Skip to content

Commit

Permalink
Fix/source mangas white screen when directly open page via url (#362)
Browse files Browse the repository at this point in the history
* 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 4e8813b where the function was adapted incorrectly with code that will never work (good job me KEKW)

* Add info about dev mode + strict mode issue
  • Loading branch information
schroda authored Jun 9, 2023
1 parent 26b48f1 commit dcd5302
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/screens/SearchAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
);
Expand Down
10 changes: 7 additions & 3 deletions src/screens/SourceMangas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit dcd5302

Please sign in to comment.