@@ -286,12 +286,11 @@ const index = (props: IndexProps): Index => {
286286 mergeSearchParameters ( ...resolveSearchParameters ( this ) )
287287 ) ;
288288
289- helper . on ( 'change' , ( { state, isPageReset } ) => {
290- localUiState = getLocalWidgetsState ( localWidgets , {
291- searchParameters : state ,
292- helper : helper ! ,
293- } ) ;
294-
289+ // Subscribe to the Helper state changes for the page before widgets
290+ // are initialized. This behavior mimics the original one of the Helper.
291+ // It makes sense to replicate it at the `init` step. We have another
292+ // listener on `change` below, once `init` is done.
293+ helper . on ( 'change' , ( { isPageReset } ) => {
295294 if ( isPageReset ) {
296295 resetPageFromWidgets ( localWidgets ) ;
297296 }
@@ -324,6 +323,19 @@ const index = (props: IndexProps): Index => {
324323 } ) ;
325324 }
326325 } ) ;
326+
327+ // Subscribe to the Helper state changes for the `uiState` once widgets
328+ // are initialized. Until the first render, state changes are part of the
329+ // configuration step. This is mainly for backward compatibility with custom
330+ // widgets. When the subscription happens before the `init` step, the (static)
331+ // configuration of the widget is pushed in the URL. That's what we want to avoid.
332+ // https://github.com/algolia/instantsearch.js/pull/994/commits/4a672ae3fd78809e213de0368549ef12e9dc9454
333+ helper . on ( 'change' , ( { state } ) => {
334+ localUiState = getLocalWidgetsState ( localWidgets , {
335+ searchParameters : state ,
336+ helper : helper ! ,
337+ } ) ;
338+ } ) ;
327339 } ,
328340
329341 render ( { instantSearchInstance } : IndexRenderOptions ) {
0 commit comments