-
Notifications
You must be signed in to change notification settings - Fork 2
NoJira: Browser history fix. #700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fdeac4a
Browser history fix.
sherakama 66bced3
Stability hack.
sherakama 0671180
Stability hack.
sherakama 651f220
Update components/Search/Search.tsx
sherakama c7f4d55
Stability hack.
sherakama b04d5b8
Merge branch 'troubleshooting' of github.com:su-sws/ood_giving_site i…
sherakama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,10 @@ import { liteClient } from 'algoliasearch/lite'; | |
| import { Hits } from 'react-instantsearch'; | ||
| import { InstantSearchNext } from 'react-instantsearch-nextjs'; | ||
| import { type SearchClient, type UiState } from 'instantsearch.js'; | ||
| import { useMemo, useEffect, useState } from 'react'; | ||
| import { SearchHit } from './SearchHit'; | ||
| import { SearchBox } from './SearchBox'; | ||
| import { SearchResultsHeader } from './SearchResultsHeader'; | ||
| import { useMemo } from 'react'; | ||
| import { NoResultsBoundary } from './NoResultsBoundary'; | ||
| import { SearchPagination } from './SearchPagination'; | ||
|
|
||
|
|
@@ -26,13 +26,14 @@ export const Search = ({ | |
| noResultsErrorText = '', | ||
| noResultsErrorTitle = '', | ||
| }: SearchProps) => { | ||
| const [key, setKey] = useState('search-component'); | ||
| const numSuggestions = useMemo(() => parseInt(suggestionsAmount, 10) || 0, [suggestionsAmount]); | ||
| const algoliaClient = liteClient( | ||
| const algoliaClient = useMemo(() => liteClient( | ||
| process.env.NEXT_PUBLIC_ALGOLIA_APP_ID, | ||
| process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY, | ||
| ); | ||
| ), []); | ||
|
|
||
| const searchClient = { | ||
| const searchClient = useMemo(() => ({ | ||
| ...algoliaClient, | ||
|
|
||
| search(requests: any[]) { | ||
|
|
@@ -54,13 +55,25 @@ export const Search = ({ | |
|
|
||
| return algoliaClient.search(requests); | ||
| }, | ||
| }; | ||
| }), [algoliaClient]); | ||
|
|
||
| // This is a workaround to reset the InstantSearch state when the component is unmounted and remounted, | ||
| // which can happen when navigating between pages in Next.js. By changing the key of the | ||
| // InstantSearch component, we force it to reset its state. | ||
| useEffect(() => { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setKey(`search-component-${Date.now()}`); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <InstantSearchNext | ||
| key={key} | ||
| indexName={process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME} | ||
| searchClient={searchClient as SearchClient} | ||
| insights | ||
| future={{ | ||
| preserveSharedStateOnUnmount: false, | ||
| }} | ||
| routing={{ | ||
| router: { | ||
| cleanUrlOnDispose: false, | ||
|
|
@@ -70,8 +83,8 @@ export const Search = ({ | |
| stateToRoute(uiState) { | ||
| const indexUiState = uiState[process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME]; | ||
| return { | ||
| q: indexUiState.query, | ||
| page: indexUiState.page, | ||
| q: indexUiState?.query, | ||
| page: indexUiState?.page, | ||
|
Comment on lines
+86
to
+87
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, it would throw an error if these weren't "safely" accessed and the indexUiState was unavailable. |
||
| } as UiState; | ||
| }, | ||
| routeToState(routeState) { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.