From 73979d6d24f0d6a66c66f1c3fc5cdc69d024edb2 Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Fri, 20 Dec 2024 16:37:13 +0530 Subject: [PATCH] Fix redirect loop in certain cases --- .../url-state/DashboardURLStateSync.svelte | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte index 4a0d7d775da..09a1382af85 100644 --- a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte +++ b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte @@ -131,13 +131,16 @@ partialExplore, metricsSpec, ); - redirectUrl.search = getUpdatedUrlForExploreState( - exploreSpec, - timeControlsState, - defaultExplorePreset, - partialExplore, - $page.url.searchParams, - ); + if (shouldUpdateUrl) { + // if we added extra url params from sessionStorage then update the url + redirectUrl.search = getUpdatedUrlForExploreState( + exploreSpec, + timeControlsState, + defaultExplorePreset, + partialExplore, + $page.url.searchParams, + ); + } // update session store when back button was pressed. if (backButtonUsed) { updateExploreSessionStore( @@ -183,7 +186,8 @@ // when there are no params set, state will be state from config yaml and any additional initial state like bookmark initState = { ...exploreStateFromYAMLConfig, - ...(initExploreState ?? {}), + // if the url changed manually then do not load data from initState, which is home bookmark or shared url's state + ...(isManualUrlChange ? {} : (initExploreState ?? {})), }; shouldUpdateUrl = !!initExploreState; } else { @@ -247,6 +251,7 @@ const newUrl = u.toString(); if (!prevUrl || prevUrl === newUrl) return; + prevUrl = newUrl; // dashboard changed so we should update the url void goto(newUrl); // also update the session store