fix: fix custom TS Monaco worker not reloading on file uri change (#8130)

This commit is contained in:
Diego Imbert
2026-02-28 07:01:23 +00:00
committed by GitHub
parent ff180de4de
commit b68ff965dd
2 changed files with 9 additions and 13 deletions
+5 -7
View File
@@ -1913,12 +1913,11 @@
})
let isTsWorkerInitialized = resource(
[() => lang, () => initialized, () => filePath],
[() => lang, () => initialized],
async () => {
if (lang !== 'typescript' || !initialized) return false
console.log('[Editor.isTsWorkerInitialized] Waiting for TS Worker...')
await waitForWorkerInitialization(filePath)
console.log('[Editor.isTsWorkerInitialized] TS Worker initialized successfully')
// Use the stable model URI (computed once at mount), not filePath which changes on rename
await waitForWorkerInitialization(uri)
return true
}
)
@@ -1929,7 +1928,7 @@
if (lang !== 'typescript' || !isTsWorkerInitialized.current) return
if (!preparedAssetsSqlQueries || preparedAssetsSqlQueries.length === 0) {
// Clear SQL queries if none exist
updateSqlQueriesInWorker(filePath, [])
updateSqlQueriesInWorker(uri, [])
return
}
@@ -1937,14 +1936,13 @@
// The worker will inject type parameters into the code that TypeScript analyzes
// Worker async function call freezes if we pass a Proxy, $state.snapshot() is very important here
updateSqlQueriesInWorker(filePath, $state.snapshot(preparedAssetsSqlQueries))
updateSqlQueriesInWorker(uri, $state.snapshot(preparedAssetsSqlQueries))
}, 250)
watch(
[
() => preparedAssetsSqlQueries,
() => lang,
() => filePath,
() => isTsWorkerInitialized.current
],
() => {
@@ -36,13 +36,12 @@ async function getWorkerClient(): Promise<(...uris: Uri[]) => Promise<ExtendedTy
}
}
export async function waitForWorkerInitialization(fileUri: string): Promise<true> {
export async function waitForWorkerInitialization(modelUri: string): Promise<true> {
const WORKER_INIT_TIMEOUT = 10000
const MAX_RETRIES = 10
const RETRY_DELAY = 300
if (!fileUri.endsWith('.ts')) fileUri += '.ts'
const uri = Uri.parse(fileUri)
const uri = Uri.parse(modelUri)
const startTime = Date.now()
@@ -84,12 +83,11 @@ export async function waitForWorkerInitialization(fileUri: string): Promise<true
* @returns Promise that resolves when the update is complete
*/
export async function updateSqlQueriesInWorker(
fileUri: string,
modelUri: string,
queries: InferAssetsSqlQueryDetails[]
): Promise<void> {
try {
if (!fileUri.endsWith('.ts')) fileUri += '.ts'
const uri = Uri.parse(fileUri)
const uri = Uri.parse(modelUri)
const uriString = uri.toString()
const workerClient = await getWorkerClient()