From fb723a7d076b4fb822d74d04d1fb06a1f0520710 Mon Sep 17 00:00:00 2001 From: Jacques Ikot Date: Thu, 23 Oct 2025 11:01:22 +0100 Subject: [PATCH] fix: handle potential null basePageId in URL generation (#41315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # PR Description ## Summary Fixes an issue where `basePageId` could be undefined during initial page load or navigation, causing errors in the URL builder. ## Changes - Added fallback to `null` for `basePageId` in Header component when undefined - Wrapped `urlBuilderFn` call in try-catch block to gracefully handle missing `basePageId` - Returns empty string for href when `basePageId` is not yet available ## Why During initial page load or navigation transitions, `currentPage?.basePageId` may not be available yet, which could cause the URL builder to throw errors. This change ensures the application handles this edge case gracefully by providing a fallback value and catching any errors that may occur. ## Automation /ok-to-test tags="@tag.Git" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 48dc01a73bbb816b63acd186d9d80eb36cdf5814 > Cypress dashboard. > Tags: `@tag.Git` > Spec: >
Thu, 23 Oct 2025 09:48:19 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No --- .../pages/AppIDE/layouts/components/Header/index.tsx | 2 +- app/client/src/pages/Editor/utils.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/client/src/pages/AppIDE/layouts/components/Header/index.tsx b/app/client/src/pages/AppIDE/layouts/components/Header/index.tsx index e5b4a4aa77..9b2c64ec1a 100644 --- a/app/client/src/pages/AppIDE/layouts/components/Header/index.tsx +++ b/app/client/src/pages/AppIDE/layouts/components/Header/index.tsx @@ -142,7 +142,7 @@ const Header = () => { ); const deployLink = useHref(viewerURL, { - basePageId: currentPage?.basePageId, + basePageId: currentPage?.basePageId || null, }); const updateApplicationDispatch = ( diff --git a/app/client/src/pages/Editor/utils.tsx b/app/client/src/pages/Editor/utils.tsx index d2e6c34d7f..a45cf5509e 100644 --- a/app/client/src/pages/Editor/utils.tsx +++ b/app/client/src/pages/Editor/utils.tsx @@ -300,7 +300,15 @@ export function useHref( const pageId = useSelector(getCurrentPageId); useEffect(() => { - if (pageId) setHref(urlBuilderFn(params)); + if (pageId) { + try { + setHref(urlBuilderFn(params)); + } catch (error) { + // If basePageId is not available yet, keep href as empty string + // This can happen during initial page load or navigation + setHref(""); + } + } }, [params, urlBuilderFn, pageId]); return href;