From 24e3daa6dcf9c7fb2fbe1c0938c753878040ffbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 3 Apr 2023 12:10:44 +0200 Subject: [PATCH] fixup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- plugins/search/package.json | 1 + .../search/src/components/SearchModal/useSearchModal.tsx | 9 +++++---- yarn.lock | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/search/package.json b/plugins/search/package.json index d4367778b7..7616a03ffd 100644 --- a/plugins/search/package.json +++ b/plugins/search/package.json @@ -67,6 +67,7 @@ "@testing-library/user-event": "^14.0.0", "@types/node": "^16.11.26", "cross-fetch": "^3.1.5", + "history": "^5.0.0", "msw": "^1.0.0" }, "files": [ diff --git a/plugins/search/src/components/SearchModal/useSearchModal.tsx b/plugins/search/src/components/SearchModal/useSearchModal.tsx index 0700898c0b..279484bd47 100644 --- a/plugins/search/src/components/SearchModal/useSearchModal.tsx +++ b/plugins/search/src/components/SearchModal/useSearchModal.tsx @@ -20,7 +20,7 @@ import { createVersionedContext, createVersionedValueMap, } from '@backstage/version-bridge'; -import { useUpdateEffect } from 'react-use'; +import useUpdateEffect from 'react-use/lib/useUpdateEffect'; /** * The state of the search modal, as well as functions for changing the modal's @@ -136,14 +136,15 @@ export function useSearchModal(initialState = false) { const parentContextValue = parentContext?.atVersion(1); const isParentContextPresent = !!parentContextValue?.state; - // Monitor route pathname changes to automatically hide the modal. - const { pathname } = useLocation(); + // Monitor route changes to automatically hide the modal. + const location = useLocation(); + const locationKey = `${location.pathname}${location.search}${location.hash}`; useUpdateEffect(() => { setState(prevState => ({ open: prevState.open, hidden: true, })); - }, [pathname]); + }, [locationKey]); // Inherit from parent context, if set. return isParentContextPresent diff --git a/yarn.lock b/yarn.lock index a70bcecc97..beb214edda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8450,6 +8450,7 @@ __metadata: "@types/node": ^16.11.26 "@types/react": ^16.13.1 || ^17.0.0 cross-fetch: ^3.1.5 + history: ^5.0.0 msw: ^1.0.0 qs: ^6.9.4 react-use: ^17.2.4