From d05c222d0a2eda0c1f48aebaafe63aa648644134 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Fri, 7 Nov 2025 16:10:52 +0530 Subject: [PATCH] regression: fallback base url for redirection (#8075) --- apps/admin/app/compat/next/helper.ts | 6 ++++-- apps/space/app/compat/next/helper.ts | 6 ++++-- apps/web/app/compat/next/helper.ts | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/admin/app/compat/next/helper.ts b/apps/admin/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/admin/app/compat/next/helper.ts +++ b/apps/admin/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") { diff --git a/apps/space/app/compat/next/helper.ts b/apps/space/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/space/app/compat/next/helper.ts +++ b/apps/space/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") { diff --git a/apps/web/app/compat/next/helper.ts b/apps/web/app/compat/next/helper.ts index fe1a98446..c04699870 100644 --- a/apps/web/app/compat/next/helper.ts +++ b/apps/web/app/compat/next/helper.ts @@ -5,8 +5,10 @@ */ export function ensureTrailingSlash(url: string): string { try { - // Handle relative URLs by creating a URL object with a dummy base - const urlObj = new URL(url, "http://dummy.com"); + const fallbackBaseUrl = + typeof window !== "undefined" && window.location.origin ? window.location.origin : "http://dummy.com"; + // Handle relative URLs by creating a URL object with a fallback base URL + const urlObj = new URL(url, fallbackBaseUrl); // Don't modify root path if (urlObj.pathname === "/") {