Skip to content

Bug: Screen Freezes When Using Back Button + Android Back Gesture Together #4349

Open

Description

@aybinv7
video5870668656622444282.mp4
  • Framework7 version: 9.x
  • Vue.js version: 3.x
  • Platform and Target: Android 10, Capacitor app (Huawei P30 Pro)
  • Live Link or CodeSandbox: Not available (bug occurs only on device)

Describe the bug

When a page has a back/return button, tapping the back button at the exact same time as performing the Android back swipe gesture causes the screen to freeze after navigating back.

To Reproduce

  1. Open any page with a back button.
  2. Tap the back button while simultaneously performing the Android back-swipe gesture.
  3. The app navigates back, then the UI freezes.

Expected behavior

The app should navigate back once without freezing.

Actual Behavior

The app navigates back, then the screen becomes frozen/unresponsive.

Screenshots

N/A

Additional context

Device: Huawei P30 Pro
Android 10
Occurs consistently when both back actions trigger at the same moment.

Activity

  1. nolimits4web commented on May 19, 2026

    @nolimits4web
    Member

    This issue was incorrectly closed on 2026-05-19 by a compromised credential (Shai-Hulud npm supply-chain worm). Reopening — apologies for the noise.

  2. aybinv7 commented on Sep 14, 2026

    @aybinv7
    Author

    Digging into this on a real device, I think I've found both the cause and — more usefully — a
    recovery path that already exists in Framework7 but is gated behind an unrelated param.

    Versions: framework7@9.0.4, framework7-vue@9.1.3, Android WebView, theme: 'md',
    browserHistory: false, all routes async.

    Cause

    navigate() has no allowPageChange check at its entry — the guard lives in load()
    (navigate.js:380) and loadBack() (back.js:308). For an async route, navigate() sets
    allowPageChange = false before invoking the handler (navigate.js:600), so when the handler
    resolves, asyncResolve has to bypass the guard to load its own page:

    // navigate.js, asyncResolve
    load(router, resolveParams, extend(options, resolveOptions), true); // ignorePageChange = true

    That bypass is necessary, but it's unconditional — it can't distinguish "the lock I set"
    from "a lock a different navigation set while I was importing." So a navigate() issued while a
    backward transition is still animating resolves and runs a forward on top of the in-flight
    backward
    . Apps using synchronous component: routes never hit this, because load()'s guard
    handles it correctly.

    Reproduction

    From a pushed page, with both routes async:

    router.back();                                    // backward transition starts
    setTimeout(() => router.navigate('/detail'), 60); // lands mid-transition

    Resulting state — history and DOM disagree:

    router.history
    // ['/', '/detail']                       <- history says previous is '/'
    
    [...router.el.children].filter(e => e.classList.contains('page')).map(e => e.dataset.name)
    // ['detail', 'detail']                   <- the '/' page element is gone

    Why it's permanent, not transient

    From there, back() finds a page-previous whose route URL equals the current one, so
    loadBack takes its same-URL early return (back.js:319) and does nothing — on every
    subsequent call. Note allowPageChange is true the whole time, so the router looks perfectly
    healthy while being completely dead. That's what makes it hard to spot.

    Framework7 already knows how to repair this

    back() contains exactly the right mismatch check — but only runs it when browserHistory is on:

    // back.js:510
    if (router.params.browserHistory && previousPageObj &&
        router.history[router.history.length - 2] !== previousPageObj.route.url) {
      router.back(router.history[router.history.length - 2], { force: true, ... });
      return router;
    }

    I ran that check by hand against the frozen router:

    step result
    corrupted state 2 pages in DOM, both /detail
    router.back() no-op, still frozen
    mismatch check expected '/' vs dom '/detail' → true
    router.back('/', { force: true }) fully recovered — history ['/'], correct page restored

    So the existing recovery works perfectly on this exact state. It just never runs, because
    whether the DOM's previous page matches router history has nothing to do with browser history —
    that gate looks incidental rather than intentional.

    Suggested fixes

    1. Recovery (one line, back.js:510) — drop the browserHistory condition:

    -if (router.params.browserHistory && previousPageObj &&
    +if (previousPageObj &&
         router.history[router.history.length - 2] !== previousPageObj.route.url) {

    This alone turns a permanent freeze into self-healing for every app with browserHistory: false
    (the default).

    2. Prevention — give the async bypass ownership semantics: have navigate()/back() bump a
    router.navigationId, capture it in asyncResolve, and return early if it no longer matches
    instead of bypassing a lock it doesn't own.

    Workaround for anyone hitting this now

    Drop the losing call. One boolean read, no queueing, so it adds no latency to the navigation
    that does win — and it must let Framework7's own recursive navigate/back calls through
    (back() re-enters itself with { force: true } after locking):

    function installNavigationGuard(router) {
      let depth = 0;
      const guard = (method) => (...args) => {
        if (depth === 0 && !router.allowPageChange) return router;
        depth += 1;
        try { return method(...args); } finally { depth -= 1; }
      };
      router.navigate = guard(router.navigate.bind(router));
      router.back = guard(router.back.bind(router));
    }
    
    // after the view exists:
    app.views.forEach(v => installNavigationGuard(v.router));

    Verified on device across 16 timing windows spanning the transition: 0 corrupted states, racing
    navigations dropped cleanly, post-transition ones navigating normally, transition time unchanged
    at 340–376ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions