Skip to content

Commit

Permalink
Merge branch 'next' into fix/defer-error
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored Jul 10, 2019
2 parents fb1a34c + 0628776 commit 65f7938
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend

this._stalledSearchDelay = stalledSearchDelay;
this._searchStalledTimer = null;
this._isSearchStalled = true;
this._isSearchStalled = false;
this._searchParameters = {
...searchParameters,
index: indexName,
Expand Down Expand Up @@ -351,7 +351,7 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
});

scheduleStalledRender() {
if (!this._isSearchStalled && !this._searchStalledTimer) {
if (!this._searchStalledTimer) {
this._searchStalledTimer = setTimeout(() => {
this._isSearchStalled = true;
this.scheduleRender();
Expand Down
19 changes: 0 additions & 19 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,25 +961,6 @@ describe('scheduleStalledRender', () => {
})
);
});

// https://github.com/algolia/instantsearch.js/pull/2623
it('does not trigger a re-`render` without results', () => {
const { searchClient } = createControlledSearchClient();
const search = new InstantSearch({
indexName: 'index_name',
searchClient,
});

search.start();

search.addWidget({
render: () => {},
});

jest.runOnlyPendingTimers();

return runAllMicroTasks();
});
});

describe('createURL', () => {
Expand Down
34 changes: 34 additions & 0 deletions src/widgets/index/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,40 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index/js/"
});
});
});

// https://github.com/algolia/instantsearch.js/pull/2623
it('does not call `render` without `lastResults`', () => {
const instance = index({ indexName: 'index_name' });
const instantSearchInstance = createInstantSearch();

const widgets = [createSearchBox(), createPagination()];

instance.addWidgets(widgets);

widgets.forEach(widget => {
expect(widget.render).toHaveBeenCalledTimes(0);
});

instance.init(
createInitOptions({
instantSearchInstance,
})
);

widgets.forEach(widget => {
expect(widget.render).toHaveBeenCalledTimes(0);
});

instance.render(
createRenderOptions({
instantSearchInstance,
})
);

widgets.forEach(widget => {
expect(widget.render).toHaveBeenCalledTimes(0);
});
});
});

describe('dispose', () => {
Expand Down
14 changes: 8 additions & 6 deletions src/widgets/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,18 @@ const index = (props: IndexProps): Index => {
render({ instantSearchInstance }) {
localWidgets.forEach(widget => {
// At this point, all the variables used below are set. Both `helper`
// and `derivedHelper` has been created at the `init` step. The attribute
// `lastResults` is set before the event `result` is emitted. At this stage,
// the event has emitted hence the value is already set.
// and `derivedHelper` have been created at the `init` step. The attribute
// `lastResults` might be `null` though. It's possible that a stalled render
// happens before the result e.g with a dynamically added index the request might
// be delayed. The render is triggered for the complete tree but some parts do
// not have results yet.

if (widget.render) {
if (widget.render && derivedHelper!.lastResults) {
widget.render({
helper: helper!,
instantSearchInstance,
results: derivedHelper!.lastResults!,
state: derivedHelper!.lastResults!._state,
results: derivedHelper!.lastResults,
state: derivedHelper!.lastResults._state,
templatesConfig: instantSearchInstance.templatesConfig,
createURL: instantSearchInstance._createAbsoluteURL,
searchMetadata: {
Expand Down

0 comments on commit 65f7938

Please sign in to comment.