From c2f6b5d49ea321ef20cfde05b80b7d8cbf569b2c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Mon, 16 Sep 2024 01:55:41 +0800 Subject: [PATCH 1/2] Fix(editor): Fix "net::ERR_INSUFFICIENT_RESOURCES" exception when the editor loads a large number of libraries --- .../Playground/CodeEditor/Editor/ata.ts | 28 ++++++++++++++++++- .../Playground/CodeEditor/Editor/hooks.ts | 4 +-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/components/Playground/CodeEditor/Editor/ata.ts b/src/components/Playground/CodeEditor/Editor/ata.ts index df03b68..61ea987 100644 --- a/src/components/Playground/CodeEditor/Editor/ata.ts +++ b/src/components/Playground/CodeEditor/Editor/ata.ts @@ -36,6 +36,31 @@ export const createATA = async (): Promise => { // @ts-expect-error // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment 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((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({ projectName: 'monaco-ts', // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment @@ -43,7 +68,7 @@ export const createATA = async (): Promise => { logger: console, fetcher: (input, init) => { try { - return fetch(input, init) + return fetchWithQueue(input, init) } catch (error) { console.error('Error fetching data:', error) } @@ -92,6 +117,7 @@ export const createATA = async (): Promise => { } return { + // eslint-disable-next-line @typescript-eslint/no-misused-promises acquireType, addListener, removeListener, diff --git a/src/components/Playground/CodeEditor/Editor/hooks.ts b/src/components/Playground/CodeEditor/Editor/hooks.ts index 2224b2f..b8aab77 100644 --- a/src/components/Playground/CodeEditor/Editor/hooks.ts +++ b/src/components/Playground/CodeEditor/Editor/hooks.ts @@ -12,8 +12,8 @@ export const useEditor = () => { const selection = input.options ? input.options.selection : null if (selection) { if ( - typeof selection.endLineNumber === 'number' && - typeof selection.endColumn === 'number' + typeof selection?.endLineNumber === 'number' && + typeof selection?.endColumn === 'number' ) { editor.setSelection(selection) editor.revealRangeInCenter(selection, ScrollType.Immediate) From 264534f47995dd4db838e2e059696a74cd5dc9fd Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 19 Sep 2024 09:59:04 +0800 Subject: [PATCH 2/2] Fix(Management): Fix base and template management unable to jump file --- src/pages/System/Tools/Base.tsx | 2 +- src/pages/System/Tools/Template.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/System/Tools/Base.tsx b/src/pages/System/Tools/Base.tsx index 148b314..d647c0b 100644 --- a/src/pages/System/Tools/Base.tsx +++ b/src/pages/System/Tools/Base.tsx @@ -1100,7 +1100,7 @@ const Base = () => { {}} + onSelectedFileChange={setEditingFileName} onChangeFileContent={handleOnChangeFileContent} showFileSelector={false} tsconfig={tsconfig} diff --git a/src/pages/System/Tools/Template.tsx b/src/pages/System/Tools/Template.tsx index 310793f..44e62c1 100644 --- a/src/pages/System/Tools/Template.tsx +++ b/src/pages/System/Tools/Template.tsx @@ -1044,7 +1044,7 @@ const Template = () => { {}} + onSelectedFileChange={setEditingFileName} onChangeFileContent={handleOnChangeFileContent} showFileSelector={false} tsconfig={tsconfig}