Skip to content
Merged
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
4 changes: 3 additions & 1 deletion e2e/playground/define/define.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ describe('define', () => {
}
})

// The filter rewrites the source with the Vite base, the preview base path of the instance
const previewBasePath = await page.evaluate(() => (window as any).__vrowzer__.previewBasePath)
expect(await result.jsonValue()).toEqual({
rewritten: '/__preview__/data.json',
rewritten: `${previewBasePath}data.json`,
untouched: '/data.json'
})
})
Expand Down
3 changes: 2 additions & 1 deletion e2e/vite-vanilla/vanilla-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ if (import.meta.hot) { import.meta.hot.accept() }

await expect.poll(() => iframeInnerText(), { timeout: 10000 }).toContain('Virtual updated')
expect(await body.getAttribute('data-hmr-token')).toBe('preserved')
const previewBasePath = await page.evaluate(() => (window as any).__vrowzer__.previewBasePath)
expect(
browserRequests.some(request => {
const url = new URL(request)
return (
url.pathname === '/__preview__/@id/__x00__virtual:invalidation' &&
url.pathname === `${previewBasePath}@id/__x00__virtual:invalidation` &&
url.searchParams.get('variant') === 'query' &&
url.searchParams.has('t')
)
Expand Down
5 changes: 4 additions & 1 deletion e2e/vite-worker-config/worker-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ describe('dedicated Worker config', () => {
expect(await page.textContent('#status')).toBe('Ready')
await expect.poll(() => page.textContent('#react-host')).toBe('React host: host define')
await expect.poll(() => iframeInnerText(), { timeout: 30000 }).toContain('Worker preview')
// The preview loads from the preview base path of the instance, under the custom basePath
const previewBasePath = await page.evaluate(() => (window as any).__vrowzer__.previewBasePath)
expect(previewBasePath).toMatch(/^\/worker-preview\/[0-9a-f]{12}\/$/)
expect(
browserResponses.some(
response => new URL(response.url).pathname === '/worker-preview/' && response.status === 200
response => new URL(response.url).pathname === previewBasePath && response.status === 200
)
).toBe(true)
})
Expand Down
2 changes: 2 additions & 0 deletions packages/vite-dev-server/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const transport = normalizeModuleRunnerTransport(
throw new Error('No active Service Worker controller found for HMR transport')
}

// The base names the runtime that owns this preview, and its Web Worker gets the port
let transport = createMessageChannelModuleRunnerTransport(navigator.serviceWorker.controller.postMessage.bind(navigator.serviceWorker.controller), {
pingInterval: hmrTimeout,
base,
})

return {
Expand Down
63 changes: 0 additions & 63 deletions packages/vite-dev-server/src/node/public-files-sync.test.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/vite-dev-server/src/node/public-files-sync.ts

This file was deleted.

36 changes: 4 additions & 32 deletions packages/vite-dev-server/src/node/server/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,9 @@ function createRegistrationContext(
} | null | undefined>,
) {
const safeModulePaths = new Set<string>()
const syncSafeModulePaths = vi.fn<(paths: string[]) => Promise<void>>(
async () => undefined,
)
const resolver = vi.fn(resolveId)

return { input, resolver, safeModulePaths, syncSafeModulePaths }
return { input, resolver, safeModulePaths }
}

function createLifecycleEnvironment(plugins: Plugin[]) {
Expand Down Expand Up @@ -274,7 +271,7 @@ describe('DevEnvironment input registration', () => {
external: 'virtual:external',
relative: 'virtual:relative',
}
const { resolver, safeModulePaths, syncSafeModulePaths } =
const { resolver, safeModulePaths } =
createRegistrationContext(input, async (id) => {
if (id === 'virtual:external') {
return { id: '/outside/external.ts', external: true }
Expand All @@ -289,7 +286,6 @@ describe('DevEnvironment input registration', () => {
input,
resolver,
safeModulePaths,
syncSafeModulePaths,
)

expect(resolver).toHaveBeenCalledTimes(4)
Expand All @@ -301,12 +297,10 @@ describe('DevEnvironment input registration', () => {
)
}
expect(safeModulePaths).toEqual(new Set(['/outside/main.ts']))
expect(syncSafeModulePaths).toHaveBeenCalledOnce()
expect(syncSafeModulePaths).toHaveBeenCalledWith(['/outside/main.ts'])
})

test('silently ignores fallback index resolution errors', async () => {
const { resolver, safeModulePaths, syncSafeModulePaths } =
const { resolver, safeModulePaths } =
createRegistrationContext(undefined, async () => {
throw new Error('index.html is not available')
})
Expand All @@ -316,7 +310,6 @@ describe('DevEnvironment input registration', () => {
undefined,
resolver,
safeModulePaths,
syncSafeModulePaths,
),
).resolves.toBeUndefined()
expect(resolver).toHaveBeenCalledWith(
Expand All @@ -325,30 +318,10 @@ describe('DevEnvironment input registration', () => {
{ isEntry: true, scan: true },
)
expect(safeModulePaths).toEqual(new Set())
expect(syncSafeModulePaths).not.toHaveBeenCalled()
})

test('syncs an input path that is already registered locally', async () => {
const resolvedInput = '/outside/main.ts'
const { resolver, safeModulePaths, syncSafeModulePaths } =
createRegistrationContext('virtual:entry', async () => ({
id: resolvedInput,
}))
safeModulePaths.add(resolvedInput)

await registerInputsAsSafeModules(
'virtual:entry',
resolver,
safeModulePaths,
syncSafeModulePaths,
)

expect(safeModulePaths).toEqual(new Set([resolvedInput]))
expect(syncSafeModulePaths).toHaveBeenCalledWith([resolvedInput])
})

test('propagates explicit input resolution errors', async () => {
const { resolver, safeModulePaths, syncSafeModulePaths } =
const { resolver, safeModulePaths } =
createRegistrationContext(
'virtual:entry',
async () => {
Expand All @@ -361,7 +334,6 @@ describe('DevEnvironment input registration', () => {
'virtual:entry',
resolver,
safeModulePaths,
syncSafeModulePaths,
),
).rejects.toThrow('explicit input failed')
})
Expand Down
8 changes: 0 additions & 8 deletions packages/vite-dev-server/src/node/server/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ export class DevEnvironment extends BaseEnvironment {
*/
_pluginContainer: EnvironmentPluginContainer<DevEnvironment> | undefined

/**
* @internal Vrowzer synchronizes safe paths to the Service Worker.
*/
_syncSafeModulePaths:
| ((paths: string[]) => Promise<void>)
| undefined

/**
* @internal
*/
Expand Down Expand Up @@ -245,7 +238,6 @@ export class DevEnvironment extends BaseEnvironment {
(id, importer, options) =>
this.pluginContainer.resolveId(id, importer, options),
this.getTopLevelConfig().safeModulePaths,
this._syncSafeModulePaths,
)
}

Expand Down
Loading
Loading