Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/react-router/src/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down