Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ class EnvironmentPluginContainer<Env extends Environment = Environment> {
}

if (id) {
partial.id = isExternalUrl(id) ? id : normalizePath(id)
partial.id =
isExternalUrl(id) || id.startsWith('\0') ? id : normalizePath(id)
return partial as PartialResolvedId
} else {
return null
Expand Down
4 changes: 4 additions & 0 deletions playground/resolve/__tests__/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ test('plugin resolved custom virtual file', async () => {
expect(await page.textContent('.custom-virtual')).toMatch('[success]')
})

test('virtual file with URL scheme should not be rewritten (#20803)', async () => {
expect(await page.textContent('.virtual-url-scheme')).toMatch('[success]')
})

test('resolve inline package', async () => {
expect(await page.textContent('.inline-pkg')).toMatch('[success]')
})
Expand Down
6 changes: 6 additions & 0 deletions playground/resolve/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ <h2>Plugin resolved virtual file (#9036)</h2>
<h2>Plugin resolved custom virtual file</h2>
<p class="custom-virtual"></p>

<h2>Virtual file with URL scheme</h2>
<p class="virtual-url-scheme"></p>

<h2>Inline package</h2>
<p class="inline-pkg"></p>

Expand Down Expand Up @@ -394,6 +397,9 @@ <h2>utf8-bom-package</h2>
import { msg as customVirtualMsg } from '@custom-virtual-file'
text('.custom-virtual', customVirtualMsg)

import { msg as virtualUrlSchemeMsg } from 'virtual-with-scheme'
text('.virtual-url-scheme', virtualUrlSchemeMsg)

import { msg as inlineMsg } from './inline-package'
text('.inline-pkg', inlineMsg)

Expand Down
16 changes: 16 additions & 0 deletions playground/resolve/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const virtualId9036 = '\0' + virtualFile9036

const customVirtualFile = '@custom-virtual-file'

const virtualFileWithScheme = 'virtual-with-scheme'
const virtualIdWithScheme = '\0https://example.com/virtual.js'

const generatedContentVirtualFile = '@generated-content-virtual-file'
const generatedContentImports = [
{
Expand Down Expand Up @@ -77,6 +80,19 @@ export default defineConfig({
}
},
},
{
name: 'virtual-url-scheme-test',
resolveId(id) {
if (id === virtualFileWithScheme) {
return virtualIdWithScheme
}
},
load(id) {
if (id === virtualIdWithScheme) {
return `export const msg = "[success] from virtual file with URL scheme"`
}
},
},
{
name: 'generated-content',
resolveId(id) {
Expand Down
Loading