From 9ded45fef80b4a7e0be237fbe0301629f862fff9 Mon Sep 17 00:00:00 2001 From: Brandon Cohen Date: Mon, 25 Apr 2022 06:47:38 -0400 Subject: [PATCH] fix: manual browser refresh would redirect to home on search page If you used the search feature and tried to manual refresh or share the link, it would reset the query. Taking you back to the home page. --- src/hooks/useSearchInput.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/useSearchInput.ts b/src/hooks/useSearchInput.ts index 8e879279a..fd4d20885 100644 --- a/src/hooks/useSearchInput.ts +++ b/src/hooks/useSearchInput.ts @@ -1,9 +1,9 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import type { UrlObject } from 'url'; -import { useEffect, useState, Dispatch, SetStateAction } from 'react'; -import useDebouncedState from './useDebouncedState'; import { useRouter } from 'next/router'; +import { Dispatch, SetStateAction, useEffect, useState } from 'react'; +import type { UrlObject } from 'url'; import type { Nullable } from '../utils/typeHelpers'; +import useDebouncedState from './useDebouncedState'; type Url = string | UrlObject; @@ -48,7 +48,7 @@ const useSearchInput = (): SearchObject => { * in a new route. If we are, then we only replace the history. */ useEffect(() => { - if (debouncedValue !== '') { + if (debouncedValue !== '' && searchOpen) { if (router.pathname.startsWith('/search')) { router.replace({ pathname: router.pathname,