waitForSuccessfulPing() — vite Function Reference
Architecture documentation for the waitForSuccessfulPing() function in client.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 62c89f60_860f_098a_c8e3_9d5d77bd220d["waitForSuccessfulPing()"] 85908ff5_4d12_826d_8235_531f91538758["client.ts"] 62c89f60_860f_098a_c8e3_9d5d77bd220d -->|defined in| 85908ff5_4d12_826d_8235_531f91538758 d1f1e08a_d62c_ffc8_40e7_039fffb49665["handleMessage()"] d1f1e08a_d62c_ffc8_40e7_039fffb49665 -->|calls| 62c89f60_860f_098a_c8e3_9d5d77bd220d f5953798_0aef_33e3_5df8_38291253d4f3["waitForSuccessfulPingInternal()"] 62c89f60_860f_098a_c8e3_9d5d77bd220d -->|calls| f5953798_0aef_33e3_5df8_38291253d4f3 2752be78_665c_da23_b678_4ae249d7fa39["close()"] 62c89f60_860f_098a_c8e3_9d5d77bd220d -->|calls| 2752be78_665c_da23_b678_4ae249d7fa39 style 62c89f60_860f_098a_c8e3_9d5d77bd220d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/client/client.ts lines 353–405
function waitForSuccessfulPing(socketUrl: string) {
if (typeof SharedWorker === 'undefined') {
const visibilityManager: VisibilityManager = {
currentState: document.visibilityState,
listeners: new Set(),
}
const onVisibilityChange = () => {
visibilityManager.currentState = document.visibilityState
for (const listener of visibilityManager.listeners) {
listener(visibilityManager.currentState)
}
}
document.addEventListener('visibilitychange', onVisibilityChange)
return waitForSuccessfulPingInternal(socketUrl, visibilityManager)
}
// needs to be inlined to
// - load the worker after the server is closed
// - make it work with backend integrations
const blob = new Blob(
[
'"use strict";',
`const waitForSuccessfulPingInternal = ${waitForSuccessfulPingInternal.toString()};`,
`const fn = ${pingWorkerContentMain.toString()};`,
`fn(${JSON.stringify(socketUrl)})`,
],
{ type: 'application/javascript' },
)
const objURL = URL.createObjectURL(blob)
const sharedWorker = new SharedWorker(objURL)
return new Promise<void>((resolve, reject) => {
const onVisibilityChange = () => {
sharedWorker.port.postMessage({ visibility: document.visibilityState })
}
document.addEventListener('visibilitychange', onVisibilityChange)
sharedWorker.port.addEventListener('message', (event) => {
document.removeEventListener('visibilitychange', onVisibilityChange)
sharedWorker.port.close()
const data: { type: 'success' } | { type: 'error'; error: unknown } =
event.data
if (data.type === 'error') {
reject(data.error)
return
}
resolve()
})
onVisibilityChange()
sharedWorker.port.start()
})
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does waitForSuccessfulPing() do?
waitForSuccessfulPing() is a function in the vite codebase, defined in packages/vite/src/client/client.ts.
Where is waitForSuccessfulPing() defined?
waitForSuccessfulPing() is defined in packages/vite/src/client/client.ts at line 353.
What does waitForSuccessfulPing() call?
waitForSuccessfulPing() calls 2 function(s): close, waitForSuccessfulPingInternal.
What calls waitForSuccessfulPing()?
waitForSuccessfulPing() is called by 1 function(s): handleMessage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free