Skip to content

feat(server): reset scheduleSearch only after all components mount #6650

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 6 commits into from
Jun 16, 2025

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jun 11, 2025

In Remix a bug was reported CR-8629, which said that there's an edge case happening where (not always) the hydrating DOM does not match the server DOM. This is caused by InfiniteHits that does not give hits if we are currently searching. Why are we searching? Because the scheduleSearch function is reset before all widgets are mounted. Until now we rely on defer to reset the function only once all widgets are mounted, but that's not reliable.

The solution: reset scheduleSearch only after the children of the InstantSearch component have been mounted. For that two new private properties are added to InstantSearch: _manuallyResetScheduleSearch (set in the useInstantSearchApi hook when initialResults are set) and a new function _resetScheduleSearch. We call this function if it exists after children have been mounted.

In this test I've updated the InitializePromise synthetic test, as it was using render from testing-library/react, which evaluates effects, which in real server environments doesn't happen.

Copy link

codesandbox-ci bot commented Jun 11, 2025

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 8d69685:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

@Haroenv Haroenv changed the title wip: reset search scheduler based on callback feat(server): reset scheduleSearch after all components mount Jun 11, 2025
Haroenv added 2 commits June 11, 2025 18:45
because we're in ssr, there's no notion of eg useEffect and we also don't search twice
defer(() => {
this.scheduleSearch = originalScheduleSearch;
})();
if (this._manuallyResetScheduleSearch) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be nicer if this is required, but for now I didn't find a good way in Vue InstantSearch to call this, also it would be a breaking change.

@Haroenv Haroenv marked this pull request as ready for review June 12, 2025 13:59
@Haroenv Haroenv requested review from a team, aymeric-giraudet and shaejaz and removed request for a team June 12, 2025 13:59
@Haroenv Haroenv changed the title feat(server): reset scheduleSearch after all components mount feat(server): reset scheduleSearch only after all components mount Jun 13, 2025
@Haroenv Haroenv merged commit 7aca759 into master Jun 16, 2025
14 checks passed
@Haroenv Haroenv deleted the feat/reset-based-on-callback branch June 16, 2025 08:25
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.

2 participants