-
Notifications
You must be signed in to change notification settings - Fork 386
Conversation
e468e05
to
ae83757
Compare
Deploy preview for react-instantsearch ready! Built with commit e468e05 https://deploy-preview-2921--react-instantsearch.netlify.app |
ae83757
to
a55cf1f
Compare
Deploy preview for react-instantsearch ready! Built with commit fc0a8fc https://deploy-preview-2921--react-instantsearch.netlify.app |
packages/react-instantsearch-core/src/connectors/connectInfiniteHits.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/index.js
Outdated
Show resolved
Hide resolved
I didn't know well about browser's scroll restoration. If you take a look at this example, It's a very simple example and the scroll restoration doesn't work there. useEffect(() => {
setResult(true);
}, []);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
{result && (
.... I need to research more, but from my understanding, the scroll is restored right after the first dom rendering, which breaks this current example which renders the big chunk of dom elements at the second render. For the same reason, when going back to a page with InstantSearch, it renders after /queries API. So the scroll is not restored. This might initiate a new RFC which saves the current search result at At the moment, we ship this as is and document how to manually restore scroll position, which is still better than before. What do you think? |
I talked to Haroen, and he said there's a render before the search api call. So I'll try to render the InfiniteHits with the cache at the first render. Then the scroll might be restored correctly. |
9f13f91
to
900519a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the new example supposed to be accessible at this address?
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/sessionStorage.js
Show resolved
Hide resolved
packages/react-instantsearch-core/src/connectors/connectInfiniteHits.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/sessionStorage.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/sessionStorage.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/index.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Yannick Croissant <yannick.croissant@algolia.com>
fixing tests |
4c64a33
to
df59325
Compare
df59325
to
5d603be
Compare
Is "argos" expected to run, or not? |
We don't rely on Argos anymore, it was too flaky :) |
packages/react-instantsearch-core/src/connectors/connectInfiniteHits.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/__tests__/sessionStorage.js
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/index.js
Outdated
Show resolved
Hide resolved
packages/react-instantsearch-dom/src/lib/infiniteHitsCache/sessionStorage.js
Show resolved
Hide resolved
…sSessionStorageCache
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit fc0a8fc:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code seems to be working well
@@ -120,8 +156,13 @@ export default createConnector({ | |||
}, | |||
|
|||
refine(props, searchState, event, index) { | |||
if (index === undefined && this._lastReceivedPage !== undefined) { | |||
index = this._lastReceivedPage + 1; | |||
const pages = Object.keys(this._cachedHits || {}).map(Number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are storing elements with a number index in an object, what about using an array to store that instead? I guess it's no big difference either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially started with an object because user could've reached the page with params like page=3
. Still in that case, an array can be used, though.
# [6.7.0](v6.5.0...v6.7.0) (2020-07-20) ### Bug Fixes * **core:** appending successful index search results by returning new object reference ([#2953](#2953)) ([0a711a7](0a711a7)) * **ssr:** remove second instance of "query" in the response "params" for SSR ([#2945](#2945)) ([bf837c5](bf837c5)), closes [#2941](#2941) ### Features * **infinite-hits:** support cache ([#2921](#2921)) ([7b26adc](7b26adc))
Summary
This PR adds a cache layer to InfiniteHits.
With the addition, you can add custom cache which is more persistent and it will give more persistent UX especially when user leaves for product detail page, and comes back to infinite hits.
How to test
Load more pages a couple of times, click "Details", come back and see if the hits are instantly loaded and the scroll is restored.
This examples uses routing because the scroll restoration works when the routing is enabled. But, of course, without the routing the cache itself works fine.