autocomplete_solr.js drives an endless reload loop in Chrome when url has #

  • webmasterbslnl
    Participant
    # 2 weeks ago

    Hi,
    We have an issue in Chrome (not in FF) where code in autocomplete_solr.js keeps reloading the page whenever a hash (#) is in the url.
    Steps to reproduce:
    – Go to https://www.(removed).nl/
    – Accept cookies (or not, its not relevant)
    – scroll down to “Beheer cookievoorkeuren” and click the link
    In your developer console you see and endless loop of page refreshes. For the end user is will seem as is you cannot scroll down the page, you keep returning to the top of the page.

    I found that om https://www.(removed).nl/content/plugins/wpsolr-pro/wpsolr/core/js/autocomplete_solr.js?ver=22.2 line 115 you register a listener on popevent. However, when an hashchange event occurs (junp to another location on same page where the location can be found after the # sign in the url) the popevent is fired too. Whether this is a Chromium bug or not I do not know but if you Google it you can find links hinting it may be so (e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=1254926). It may be that it is normal (in Chrome, in FF the same popevent is NOT fired). The result is that a reload is triggered further down autocomplete_solr.js. The reload triggers another popevent en there we are in an endless loop.

    I would like a solution for this problem. But as I have no idea why the event listener for popevent is there and what it is for I can’t fix it. For instance: setting is_show_url_parameters to false would break the loop but it will surely break some function of WPSolr too. Also I do not know where to set the value of that variable. Also, fiddling with the WPSolr code I would rather avoid. Do you have any ideas?

    Thanks for your help,
    Harmen

    • This topic was modified 2 weeks ago by wpsolr.
    wpsolr
    Keymaster
    # 2 weeks ago

    I confirm your issue. For chrome, and Safari.
    Digging in the issue right now…

    wpsolr
    Keymaster
    # 2 weeks ago

    As a workaround, Line 114 you could add a condition to prevent ‘#’ urls to trigger the event:

    window.addEventListener("popstate", function (e) {
        if (wp_localize_script_autocomplete.data.is_show_url_parameters && !window.location.href.indexOf('#')) {
            call_ajax_search_timer(window.location.search, false, true);
        }
    });
    webmasterbslnl
    Participant
    # 2 weeks ago

    Thanks, you were quick to answer! I will implement it on our site. This will not break any functionality of WPSolr itself? Will you be adding it to the next version of the plugin?

    wpsolr
    Keymaster
    # 2 weeks ago

    It’s already part of the next release: https://trello.com/c/40zHUwhX/193-fix-url-with-hash-caracter-triggering-endless-popstate-events

    This code is about managing the back button history with WPSOLR Ajax. I can’t see this small fix breaking anything, but We will be sure only after all automated tests prior to next release.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.