Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(core): hydrated always is false on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Jan 23, 2019
1 parent b95d1b8 commit 8851dec
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
39 changes: 39 additions & 0 deletions src/components/__tests__/InstantSearchSsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,42 @@ it('does not start too many times', async () => {

expect(startSpy).toHaveBeenCalledTimes(1);
});

it('does not dispose if not yet started', async () => {
const { instantsearch: instance, rootMixin } = createInstantSearch({
indexName: 'bla',
searchClient: createFakeClient(),
});

const disposeSpy = jest.spyOn(instance, 'dispose');

const wrapper = mount(InstantSearchSsr, {
...rootMixin,
components: {
AisSearchBox: SearchBox,
},
slots: {
default: SearchBox,
},
});

wrapper.destroy();

// does not yet call, since instance isn't started
expect(disposeSpy).toHaveBeenCalledTimes(0);

const wrapperTwo = mount(InstantSearchSsr, {
...rootMixin,
components: {
AisSearchBox: SearchBox,
},
slots: {
default: SearchBox,
},
});
await Vue.nextTick();

wrapperTwo.destroy();

expect(disposeSpy).toHaveBeenCalledTimes(1);
});
6 changes: 3 additions & 3 deletions src/util/createInstantSearchComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export const createInstantSearchComponent = component =>

// TODO: remove this once algolia/instantsearch.js#3415 is used
this.instantSearchInstance.helper = null;

// a hydrated instance will no longer be hydrated once disposed, and starts from scratch
this.instantSearchInstance.hydrated = false;
}

// a hydrated instance will no longer be hydrated once disposed, and starts from scratch
this.instantSearchInstance.hydrated = false;
},
},
component
Expand Down

0 comments on commit 8851dec

Please sign in to comment.