-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): don't go into an infinite reload loop, don't fail if "e…
…rror" event is caught (#4618)
- Loading branch information
1 parent
2ff3533
commit ec3d694
Showing
2 changed files
with
52 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,5 @@ | ||
// it's possible that import was not optimized yet | ||
async function tryImport(id: string, tries = 20): Promise<any> { | ||
try { | ||
return await import(id) | ||
} | ||
catch (cause) { | ||
if (tries <= 0) { | ||
location.reload() | ||
throw new Error(`Failed to import ${id}.`, { cause }) | ||
} | ||
|
||
await new Promise(resolve => setTimeout(resolve, 0)) | ||
return await tryImport(id, tries - 1) | ||
} | ||
} | ||
|
||
export async function importId(id: string) { | ||
const name = `/@id/${id}` | ||
// TODO: this import _should_ always work, but sometimes it doesn't | ||
// this is a workaround until we can properly debug it - maybe server is not ready? | ||
// @ts-expect-error mocking vitest apis | ||
return __vi_wrap_module__(tryImport(name)) | ||
return __vi_wrap_module__(import(name)) | ||
} |