OpenCode commited on
Commit
fb3eaf4
·
1 Parent(s): 96029fb

fix: close mobile sidebar before history back

Browse files
Files changed (2) hide show
  1. static/app.js +8 -5
  2. tests/test_browser.py +17 -0
static/app.js CHANGED
@@ -2488,6 +2488,13 @@ function updateSidebarHeader() {
2488
  updateSidebarExpandButton();
2489
  }
2490
 
 
 
 
 
 
 
 
2491
  function setSidebarExpanded(expanded) {
2492
  if (!DOM.leftSidebar) return;
2493
  DOM.leftSidebar.classList.toggle("expanded-wide", Boolean(expanded));
@@ -2530,13 +2537,9 @@ function handleSidebarBackNavigation(event) {
2530
  }
2531
  if (!STATE.isMobile || (!STATE.leftSidebarOpen && !STATE.rightSidebarOpen) || !sidebarHistoryActive)
2532
  return false;
2533
- if (event.state?.voiceSidebarGuard) {
2534
- sidebarHistoryRoute = location.href;
2535
- return false;
2536
- }
2537
  sidebarHistoryActive = false;
2538
  sidebarHistoryRoute = "";
2539
- ROUTER.apply();
2540
  STATE.leftSidebarOpen = false;
2541
  STATE.rightSidebarOpen = false;
2542
  updateSidebarVisibility();
 
2488
  updateSidebarExpandButton();
2489
  }
2490
 
2491
+ function sidebarHistoryRouteKey(rawUrl) {
2492
+ const url = new URL(rawUrl, location.href);
2493
+ const params = new URLSearchParams(url.search);
2494
+ ["sidebar", "filters", "wide"].forEach(key => params.delete(key));
2495
+ return url.origin + url.pathname + (params.toString() ? "?" + params.toString() : "");
2496
+ }
2497
+
2498
  function setSidebarExpanded(expanded) {
2499
  if (!DOM.leftSidebar) return;
2500
  DOM.leftSidebar.classList.toggle("expanded-wide", Boolean(expanded));
 
2537
  }
2538
  if (!STATE.isMobile || (!STATE.leftSidebarOpen && !STATE.rightSidebarOpen) || !sidebarHistoryActive)
2539
  return false;
2540
+ if (sidebarHistoryRouteKey(sidebarHistoryRoute) !== sidebarHistoryRouteKey(location.href)) return false;
 
 
 
2541
  sidebarHistoryActive = false;
2542
  sidebarHistoryRoute = "";
 
2543
  STATE.leftSidebarOpen = false;
2544
  STATE.rightSidebarOpen = false;
2545
  updateSidebarVisibility();
tests/test_browser.py CHANGED
@@ -527,6 +527,23 @@ class BrowserInteractionTests(unittest.TestCase):
527
  finally:
528
  context.close()
529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  def test_mobile_back_closes_visible_drawer_before_leaving_search(self):
531
  context, page, errors = self.open_page({"width": 390, "height": 844})
532
  try:
 
527
  finally:
528
  context.close()
529
 
530
+ def test_mobile_back_closes_drawer_before_restoring_route_history(self):
531
+ context, page, errors = self.open_page({"width": 390, "height": 844})
532
+ try:
533
+ page.goto(self.base_url + "/?sidebar=0", wait_until="domcontentloaded")
534
+ page.locator("#search-input").wait_for(state="visible")
535
+ page.locator("#hamburger-btn").click()
536
+ page.evaluate("ROUTER.navigate('repo', 'Test')")
537
+ page.wait_for_function("STATE.mode === 'repo' && STATE.leftSidebarOpen")
538
+ page.evaluate("history.back()")
539
+ page.wait_for_function("STATE.mode === 'repo' && !STATE.leftSidebarOpen")
540
+ self.assertIn("/Test", page.url)
541
+ page.evaluate("history.back()")
542
+ page.wait_for_function("STATE.mode === 'global'")
543
+ self.assertEqual(errors, [])
544
+ finally:
545
+ context.close()
546
+
547
  def test_mobile_back_closes_visible_drawer_before_leaving_search(self):
548
  context, page, errors = self.open_page({"width": 390, "height": 844})
549
  try: