Fix(editor): Fix "net::ERR_INSUFFICIENT_RESOURCES" exception when the editor loads a large number of libraries
This commit is contained in:
@@ -36,6 +36,31 @@ export const createATA = async (): Promise<TypeHelper> => {
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const ts = await import('https://esm.sh/typescript@5.3.3')
|
const ts = await import('https://esm.sh/typescript@5.3.3')
|
||||||
|
|
||||||
|
const maxConcurrentRequests = 50
|
||||||
|
let activeRequests = 0
|
||||||
|
const requestQueue: Array<() => void> = []
|
||||||
|
const fetchWithQueue = (input: RequestInfo | URL, init?: RequestInit | undefined) =>
|
||||||
|
new Promise<Response>((resolve, reject) => {
|
||||||
|
const attemptRequest = () => {
|
||||||
|
if (activeRequests < maxConcurrentRequests) {
|
||||||
|
activeRequests++
|
||||||
|
fetch(input, init)
|
||||||
|
.then((response) => resolve(response))
|
||||||
|
.catch((error) => reject(error))
|
||||||
|
.finally(() => {
|
||||||
|
activeRequests--
|
||||||
|
if (requestQueue.length > 0) {
|
||||||
|
requestQueue.shift()?.()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
requestQueue.push(attemptRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attemptRequest()
|
||||||
|
})
|
||||||
|
|
||||||
const ata = setupTypeAcquisition({
|
const ata = setupTypeAcquisition({
|
||||||
projectName: 'monaco-ts',
|
projectName: 'monaco-ts',
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
@@ -43,7 +68,7 @@ export const createATA = async (): Promise<TypeHelper> => {
|
|||||||
logger: console,
|
logger: console,
|
||||||
fetcher: (input, init) => {
|
fetcher: (input, init) => {
|
||||||
try {
|
try {
|
||||||
return fetch(input, init)
|
return fetchWithQueue(input, init)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching data:', error)
|
console.error('Error fetching data:', error)
|
||||||
}
|
}
|
||||||
@@ -92,6 +117,7 @@ export const createATA = async (): Promise<TypeHelper> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
acquireType,
|
acquireType,
|
||||||
addListener,
|
addListener,
|
||||||
removeListener,
|
removeListener,
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ export const useEditor = () => {
|
|||||||
const selection = input.options ? input.options.selection : null
|
const selection = input.options ? input.options.selection : null
|
||||||
if (selection) {
|
if (selection) {
|
||||||
if (
|
if (
|
||||||
typeof selection.endLineNumber === 'number' &&
|
typeof selection?.endLineNumber === 'number' &&
|
||||||
typeof selection.endColumn === 'number'
|
typeof selection?.endColumn === 'number'
|
||||||
) {
|
) {
|
||||||
editor.setSelection(selection)
|
editor.setSelection(selection)
|
||||||
editor.revealRangeInCenter(selection, ScrollType.Immediate)
|
editor.revealRangeInCenter(selection, ScrollType.Immediate)
|
||||||
|
|||||||
Reference in New Issue
Block a user