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 4e8813b526 where the function was adapted incorrectly with code that will never work (good job me KEKW)

* Add info about dev mode + strict mode issue
This commit is contained in:
schroda
2023-06-10 00:42:26 +02:00
committed by GitHub
parent 26b48f15c5
commit dcd5302a26
2 changed files with 10 additions and 3 deletions

View File

@@ -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`),
);

View File

@@ -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],