Skip to content

Loading…

changePage stops working after JS error in show event #5249

Closed
bittlelum opened this Issue · 3 comments

4 participants

@bittlelum

I've run into an issue where changePage stops working when the new page throws an exception in a "show" event handler. It seems that, since that exception is uncaught, it errors out the changePage method, and so isPageTransitioning never gets unset. As a result, future calls to changePage never actually run, they just push onto the transition queue and return, so navigation is disabled without any indication of a problem (apart from an error in the console).

The problem is with this line, in transitionPages(), line 508 of jquery.mobile.navigation.js in 1.2:

toPage.data( "page" )._trigger( "show", null, { prevPage: fromPage || $( "" ) } );

(incidentally, I suspect the same would happen in the fromPage's "hide" event above that, although I haven't tested that).

I'm using 1.1.1, but it seems to still be present in 1.2.

@gabrielschulhof

Well, adding a try block around these lines (and it's not just the "show", but also the "hide" of the previous page) is not a good idea, because these errors need to be propagated all the way to the console, otherwise you will never know that they have occurred.

Nevertheless, the navigation should be robust enough to continue despite them.

@jerone

I agree with @gabrielschulhof. These errors should be shown in the console. I had a similar issue with the same line in jquery.mobile.js. A listitem with link and then overruling the click to open a page. I forgot to cancel the original event.

listitem.on("vclick", function (e) {
    var href = $(this).find("a").attr("href");
    if (href) {
        $.mobile.changePage(href);
    }
});

I changed it to:

listitem.on("vclick click", function (e) {
    var href = $(this).find("a").attr("href");
    if (href) {
        $.mobile.changePage(href);

        // prevent slower event (click);
        return false;
    }
});
@arschmitz
jQuery Foundation member

Im closing this as stale

@arschmitz arschmitz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.