Skip to content

Commit 3ce2f64

Browse files
committed
MAGE-1241 Dynamically derive container at run time for dynamic widgets
1 parent 4d63620 commit 3ce2f64

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

view/frontend/web/js/instantsearch.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,20 @@ define([
199199
return;
200200
}
201201

202+
if (algoliaConfig.instant.isDynamicFacetsEnabled && this.isDynamicFacetsEligible(type)) {
203+
// we cannot pre-bake the dynamicWidget - defer and package the type with the config
204+
this.dynamicWidgets.push({ ...config, type });
205+
return;
206+
}
207+
202208
let widget = instantsearch.widgets[type];
203209

204210
if (config.panelOptions) {
205211
widget = instantsearch.widgets.panel(config.panelOptions)(widget);
206212
delete config.panelOptions; // facet config attribute only NOT IS widget attribute
207213
}
208214

209-
const configuredWidget = widget(config);
210-
211-
if (algoliaConfig.instant.isDynamicFacetsEnabled && this.isDynamicFacetsEligible(type)) {
212-
this.dynamicWidgets.push(configuredWidget);
213-
return;
214-
}
215-
216-
search.addWidgets([configuredWidget]);
215+
search.addWidgets([widget(config)]);
217216
},
218217

219218
/**
@@ -227,7 +226,18 @@ define([
227226
search.addWidget(
228227
dynamicWidgets({
229228
container: '#instant-search-facets-container',
230-
widgets: this.dynamicWidgets.map(widget => container => widget)
229+
widgets: this.dynamicWidgets.map(config => {
230+
const { type, ...raw } = config;
231+
const widget = instantsearch.widgets[type];
232+
// The dynamicWidgets container must be derived at run time
233+
return container => {
234+
const newConfig = {
235+
...raw,
236+
container
237+
};
238+
return widget(newConfig);
239+
};
240+
})
231241
})
232242
);
233243
},

0 commit comments

Comments
 (0)