Skip to content

Commit

Permalink
fix: manual browser refresh would redirect to home on search page
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OwsleyJr authored and Fallenbagel committed May 21, 2022
1 parent 54067e0 commit 9ded45f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/hooks/useSearchInput.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9ded45f

Please sign in to comment.