From 23089661b90d26bdb60533a64302c639c40c7122 Mon Sep 17 00:00:00 2001 From: Eduard Fischer-Szava <50618110+EduardF1@users.noreply.github.com> Date: Sun, 7 Jun 2026 03:21:51 +0200 Subject: [PATCH] feat(start): support serving assets via a relative base url Fixes #5966 --- packages/react-router/src/Asset.tsx | 8 +++++++- .../src/start-manifest-plugin/manifestBuilder.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/react-router/src/Asset.tsx b/packages/react-router/src/Asset.tsx index e3fa1c06de..2bf529819c 100644 --- a/packages/react-router/src/Asset.tsx +++ b/packages/react-router/src/Asset.tsx @@ -136,7 +136,13 @@ function Script({ const normSrc = (() => { try { const base = document.baseURI || window.location.href - return new URL(attrs.src, base).href + // If the src is explicitly relative and base is present, construct it carefully + // Without returning absolute URLs that break iframe/embedded deployments + const url = new URL(attrs.src, base) + if (attrs.src.startsWith('./') && !base.startsWith('http')) { + return attrs.src + } + return url.href } catch { return attrs.src } diff --git a/packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts b/packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts index 6f27f37d4d..3e31cb38b5 100644 --- a/packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts +++ b/packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts @@ -263,7 +263,14 @@ export function createManifestAssetResolvers( return cachedPath } - const assetPath = joinURL(basePath, fileName) + let assetPath = joinURL(basePath, fileName) + if (basePath === './') { + // Avoid inserting a leading slash if base path is purely relative + assetPath = './' + fileName + } else if (basePath.startsWith('./') && assetPath.startsWith('/')) { + assetPath = '.' + assetPath + } + assetPathByFileName.set(fileName, assetPath) return assetPath }