Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ To help you migrate, please refer to the migration guide: https://community.algo
);
}

// The routing manager widget is always added manually at the last position.
// By removing it from the last position and adding it back after, we ensure
// it keeps this position.
// fixes #3148
const lastWidget = this.widgets.pop();

widgets.forEach(widget => {
// Add the widget to the list of widget
if (widget.render === undefined && widget.init === undefined) {
Expand All @@ -204,6 +210,9 @@ To help you migrate, please refer to the migration guide: https://community.algo
this.widgets.push(widget);
});

// Second part of the fix for #3148
if (lastWidget) this.widgets.push(lastWidget);

// Init the widget directly if instantsearch has been already started
if (this.started && Boolean(widgets.length)) {
this.searchParameters = this.widgets.reduce(enhanceConfiguration({}), {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ describe('InstantSearch lifecycle', () => {
});
});

describe('when we have 5 widgets', () => {
describe('when we have 5 widgets (at once)', () => {
let widgets;

beforeEach(() => {
widgets = range(5);
widgets = widgets.map((widget, widgetIndex) => ({
widgets = range(5).map((widget, widgetIndex) => ({
init() {},
getConfiguration: sinon.stub().returns({ values: [widgetIndex] }),
}));
widgets.forEach(search.addWidget, search);
search.addWidgets(widgets);
search.start();
});

Expand Down