Skip to content
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

fix(createURL): correctly remove page in state #4679

Merged
merged 3 commits into from
Mar 24, 2021
Merged

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Mar 17, 2021

Summary

createURL didn't reset the page because it uses SearchParameter methods vs. helper methods which get the page reset automatically.

Result

fixes algolia/vue-instantsearch#932

all createURLs now reset the page as expected

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 17, 2021

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 0767ed8:

Sandbox Source
InstantSearch.js Configuration

@Haroenv
Copy link
Contributor Author

Haroenv commented Mar 17, 2021

In the future we should rely on getWidgetSearchParameters IMO, although at the moment that doesn't reset the page either (otherwise it doesn't work when pagination or infinite hits isn't the last widget). Maybe isPageReset could be useful somehow? Or call this.getWidgetSearchParameters().resetPage() in refine and createURL, which could make sense too?

@jonathan-bird
Copy link

jonathan-bird commented Mar 17, 2021

@Haroenv That was pretty much my approach too when I created my hacky workaround but thinking about it more, you want pretty much every facet in the URL except pagination so I think a "reset pagination" type method is the best way to handle it.

Forked & updated the code sandbox to show it working in action with routing (super rough, don't judge me :D) https://codesandbox.io/s/instantsearchjs-forked-pgrci?file=/src/app.js

@Haroenv Haroenv marked this pull request as ready for review March 18, 2021 09:42
@eunjae-lee
Copy link
Contributor

In the future we should rely on getWidgetSearchParameters IMO, although at the moment that doesn't reset the page either (otherwise it doesn't work when pagination or infinite hits isn't the last widget). Maybe isPageReset could be useful somehow? Or call this.getWidgetSearchParameters().resetPage() in refine and createURL, which could make sense too?

While this PR looks good to me, could you rephrase what you said?

@Haroenv
Copy link
Contributor Author

Haroenv commented Mar 18, 2021

If you check the implementations of getWidgetSearchParameters, you'll see that none of them reset the page. That's because the actual page reset logic is done in the index widget's change listener on the helper.

That means that even if we use getWidgetSearchParameters for createURL and refine, we still would have to reset the page after retrieving the state.

It could be quite interesting longer-term to use a createURL based on UIState alone though, as well as relying on uiState alone for refine. I think it should be possible in theory, but will have breaking changes for non-builtin widgets relying only on the helper state. Maybe in a major version?

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. That sounds like an interesting approach, but as you said, in a major version.

This PR looks good to me.

@Haroenv Haroenv merged commit 48c080e into master Mar 24, 2021
@Haroenv Haroenv deleted the fix/create-url-page branch March 24, 2021 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hierarchical Menu including ?page data when in the route state
3 participants