From 5be42ebbd374feca5b012e8fde36f5e727fdf3a3 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:26:22 +0530 Subject: [PATCH] fix(nc-gui): append reload_attempt query param after hash url (#9352) --- packages/nc-gui/plugins/error-handler.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/plugins/error-handler.ts b/packages/nc-gui/plugins/error-handler.ts index a67bd8540e..eddeb14e6b 100644 --- a/packages/nc-gui/plugins/error-handler.ts +++ b/packages/nc-gui/plugins/error-handler.ts @@ -4,13 +4,25 @@ export default defineNuxtPlugin((nuxtApp) => { const QUERY_PARAM_NAME = 'reload_attempt' const reload = () => { - const searchParams = new URLSearchParams(window.location.search) + const url = new URL(window.location.href) + const hash = url.hash || '' // Get the current hash part + + // Extract path and query from the hash + const [path, queryString] = hash.split('?') + const searchParams = new URLSearchParams(queryString || '') const currentRetry = Number(searchParams.get(QUERY_PARAM_NAME)) || 0 + if (currentRetry < MAX_RETRIES) { console.log('[nuxt]: Reloading due to chunk error') searchParams.set(QUERY_PARAM_NAME, (currentRetry + 1).toString()) - // Changing the search also causes a refresh - window.location.search = searchParams.toString() + + // Rebuild the hash with updated query params + const newHash = `${path}?${searchParams.toString()}` + url.hash = newHash + + window.location.replace(url.toString()) + // sometimes replace will not causes a refresh so we have to reload page + window.location.reload() } }