From 48486737c2503036de4bf7e71fb3838b0151887e Mon Sep 17 00:00:00 2001 From: psrok1 Date: Tue, 20 Aug 2024 16:27:50 +0200 Subject: [PATCH] Fix: 'Back' doesn't work in RecentView because of navigation loop --- .../RecentView/Views/RecentView.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mwdb/web/src/components/RecentView/Views/RecentView.tsx b/mwdb/web/src/components/RecentView/Views/RecentView.tsx index 1c86225b..d9957896 100644 --- a/mwdb/web/src/components/RecentView/Views/RecentView.tsx +++ b/mwdb/web/src/components/RecentView/Views/RecentView.tsx @@ -37,15 +37,18 @@ export function RecentView(props: Props) { // Optionally convert query if only hash or hashes were provided query = multiFromHashes(query); // Set query in URL (currentQuery, countingEnabled) - setSearchParams((prev) => { - if (query === prev.get("query")) - throw new Error("Tried to set the same query twice"); - return { - ...Object.fromEntries(prev.entries()), - q: query, - count: prev.get("count") === "1" ? "1" : "0", - }; - }); + setSearchParams( + (prev) => { + if (query === prev.get("query")) + throw new Error("Tried to set the same query twice"); + return { + ...Object.fromEntries(prev.entries()), + q: query, + count: prev.get("count") === "1" ? "1" : "0", + }; + }, + { replace: true } + ); }, [setSearchParams] );