Skip to content

Commit fa1d260

Browse files
authored
fix(rsc): ensure trailing slash of BASE_URL (#589)
1 parent 1b4e0f0 commit fa1d260

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/plugin-rsc/src/browser.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function initialize(): void {
1010
load: async (id) => {
1111
if (!import.meta.env.__vite_rsc_build__) {
1212
// @ts-ignore
13-
return __vite_rsc_raw_import__(import.meta.env.BASE_URL + id.slice(1))
13+
return __vite_rsc_raw_import__(
14+
withTrailingSlash(import.meta.env.BASE_URL) + id.slice(1),
15+
)
1416
} else {
1517
const import_ = clientReferences.default[id]
1618
if (!import_) {
@@ -21,3 +23,12 @@ function initialize(): void {
2123
},
2224
})
2325
}
26+
27+
// Vite normalizes `config.base` to have trailing slash, but not for `import.meta.env.BASE_URL`.
28+
// https://github.com/vitejs/vite/blob/27a192fc95036dbdb6e615a4201b858eb64aa075/packages/vite/src/shared/utils.ts#L48-L53
29+
function withTrailingSlash(path: string): string {
30+
if (path[path.length - 1] !== '/') {
31+
return `${path}/`
32+
}
33+
return path
34+
}

0 commit comments

Comments
 (0)