-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
39 lines (36 loc) · 1.37 KB
/
Copy pathvite.config.ts
File metadata and controls
39 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { type Plugin, defineConfig } from 'vite'
// REPRO=patch -> drop one bundled-dev-update (issue 2: lost patch is undetectable)
// REPRO=reload -> drop one full-reload reply (issue 1: reloadPending is sticky)
const mode = process.env.REPRO ?? 'patch'
export default defineConfig({
experimental: { bundledDev: true },
plugins: [dropOneMessage(mode === 'reload' ? 'full-reload' : 'bundled-dev-update')],
})
/**
* Drops the first WS message of `type` sent to each client, then passes everything through.
*
* Stands in for a message lost in transit. In our production setup the equivalent loss happens
* inside Vite itself: `bundledDev.ts` returns without replying when `this.clients.getId(client)`
* misses, which it can right after a server restart.
*/
function dropOneMessage(type: string): Plugin {
return {
name: 'repro-drop-one-message',
apply: 'serve',
configureServer(server) {
let dropped = false
server.ws.on('vite:client:connect', (_data, client) => {
const send = client.send.bind(client)
client.send = (payload: unknown) => {
const p = payload as { type?: string; url?: string }
if (!dropped && p?.type === type) {
dropped = true
console.log(`\n[repro] DROPPED ${type}${p.url ? ` (${p.url})` : ''}\n`)
return
}
send(payload)
}
})
},
}
}