-
Notifications
You must be signed in to change notification settings - Fork 530
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(status): send render event when loading starts #5127
Conversation
Without this it's impossible to use `loading` for anything. I opted to only emit the event, as calling render on the widgets would require changes in all the tests. If we render (fully), you still don't get updated of `loading` initially because `render` only gets called when there are results: https://github.com/algolia/instantsearch.js/blob/4d43bd8292446101742a10d1da9f042f780d8d45/src/widgets/index/index.ts#L573-L575 To fix all of these inconsistencies, we should join `init` and `render` in a single function (always calling render, even if it's the first render, also when there's no results), but this would be a significant breaking change, so shouldn't be done lightly
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 9c4c8e6:
|
expect(renderSpy).toHaveBeenCalledTimes(2); | ||
expect(renderSpy).toHaveBeenNthCalledWith(1, { widgetRenderTimes: 0 }); | ||
expect(renderSpy).toHaveBeenNthCalledWith(2, { widgetRenderTimes: 1 }); |
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.
This isn't obvious what the behavior is when just reading those lines, can you add comments?
@@ -185,7 +185,7 @@ describe('status', () => { | |||
}); | |||
|
|||
test('lets users render on error with the `render` event', async () => { | |||
expect.assertions(4); | |||
// expect.assertions(4); |
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.
Why is this commented?
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> **Summary** <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> Introduces `status` and `error` in the response of `useInstantSearch`, as well as a new option on `useInstantSearch` to indicate errors in the search lifecycle should be caught. built on top of algolia/instantsearch#5127 **Result** <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> ```jsx function Status() { const { status, error } = useInstantSearch({ catchError: true }); return ( <> <span>Search status: {status}</span> {error && <span>a search error occurred: {error.message}</span>} </> ); } ``` FX-1769
…earch#3645) <!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. --> **Summary** <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? Are there any linked issues? --> Introduces `status` and `error` in the response of `useInstantSearch`, as well as a new option on `useInstantSearch` to indicate errors in the search lifecycle should be caught. built on top of #5127 **Result** <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. --> ```jsx function Status() { const { status, error } = useInstantSearch({ catchError: true }); return ( <> <span>Search status: {status}</span> {error && <span>a search error occurred: {error.message}</span>} </> ); } ``` FX-1769
Without this it's impossible to use
loading
for anything. I opted to only emit the event, as calling render on the widgets would require changes in all the tests.If we render (fully), you still don't get updated of
loading
initially becauserender
only gets called when there are results:https://github.com/algolia/instantsearch.js/blob/4d43bd8292446101742a10d1da9f042f780d8d45/src/widgets/index/index.ts#L573-L575
To fix all of these inconsistencies, we should join
init
andrender
in a single function (always calling render, even if it's the first render, also when there's no results), but this would be a significant breaking change, so shouldn't be done lightly.Without this PR,
useInstantSearch
in React InstantSearch Hooks doesn't get updated when the status changes toloading
, as that doesn't emit render (yet)