From ee15c8a10c113a5316cdb60caedc2b4d59d05c17 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Thu, 16 Nov 2023 09:49:23 +0100 Subject: [PATCH] fix(browser): wait until vite finishes prebundling of vitest dependencies --- packages/browser/src/client/main.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/browser/src/client/main.ts b/packages/browser/src/client/main.ts index 0780333421f8..94a279c3829c 100644 --- a/packages/browser/src/client/main.ts +++ b/packages/browser/src/client/main.ts @@ -94,8 +94,16 @@ async function reportUnexpectedError(rpc: typeof client.rpc, type: string, error ws.addEventListener('open', async () => { await loadConfig() - const { getSafeTimers } = await importId('vitest/utils') as typeof import('vitest/utils') - const safeRpc = createSafeRpc(client, getSafeTimers) + let safeRpc: typeof client.rpc + try { + // if importing /@id/ failed, we reload the page waiting until Vite prebundles it + const { getSafeTimers } = await importId('vitest/utils') as typeof import('vitest/utils') + safeRpc = createSafeRpc(client, getSafeTimers) + } + catch (err) { + location.reload() + return + } stopErrorHandler() stopRejectionHandler()