This is an automated email from the ASF dual-hosted git repository.

hughhhh pushed a commit to branch hughhhh/zagreb-embed-page
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/hughhhh/zagreb-embed-page by 
this push:
     new 5e3211b1556 fix(dashboard): keep window.history in sync when updating 
Rison URL
5e3211b1556 is described below

commit 5e3211b1556933bf8307b3270dac711630e89094
Author: Hugh A Miles II <[email protected]>
AuthorDate: Wed May 27 10:01:41 2026 -0400

    fix(dashboard): keep window.history in sync when updating Rison URL
    
    `updateUrlWithUnmatchedFilters` only routed through the supplied react-
    router history when one was passed. With a `BrowserRouter` this also
    propagates to `window.location`, but under `createMemoryHistory` (used
    in `UrlFilters/Vertical.test.tsx`) it does not — so the subsequent
    `useEffect` on `location.search` re-ran `getUrlFilterIndicators()`,
    which reads `window.location.search`, and re-populated the chip list
    with the stale URL, causing the removed chip to flash back.
    
    Always call `window.history.replaceState` and then, if a history was
    supplied, also call `history.replace`. Idempotent with `BrowserRouter`,
    correct with `MemoryRouter`.
    
    Co-Authored-By: Claude Opus 4.7 <[email protected]>
---
 superset-frontend/src/dashboard/util/risonFilters.ts | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/superset-frontend/src/dashboard/util/risonFilters.ts 
b/superset-frontend/src/dashboard/util/risonFilters.ts
index 2c1eea8f7d7..d9b4ead12a0 100644
--- a/superset-frontend/src/dashboard/util/risonFilters.ts
+++ b/superset-frontend/src/dashboard/util/risonFilters.ts
@@ -346,17 +346,22 @@ export function updateUrlWithUnmatchedFilters(
       }
     }
 
+    // Always keep window.history in sync so callers that read
+    // `window.location.search` (e.g. `getRisonFilterParam`) see the update.
+    // With a real `BrowserRouter`, `history.replace` would do this too — but
+    // under a `createMemoryHistory` (used in tests, or in some embedded
+    // contexts) it does not, and we'd leak the stale URL into the next
+    // `getRisonFilterParam()` call.
+    window.history.replaceState(
+      window.history.state,
+      '',
+      currentUrl.toString(),
+    );
     if (history) {
       history.replace({
         pathname: currentUrl.pathname,
         search: currentUrl.search,
       });
-    } else {
-      window.history.replaceState(
-        window.history.state,
-        '',
-        currentUrl.toString(),
-      );
     }
   } catch (error) {
     console.warn('Failed to update URL with unmatched filters:', error);

Reply via email to