From cb74ba803de69cacb76bfca8137f95a004a4f156 Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Mon, 22 Jun 2026 12:58:02 +0700 Subject: [PATCH] fix(account-data-editor): restore Ace load ordering --- .../__tests__/account-data-editor.test.tsx | 16 ++++++++++++++-- .../account-data-editor/account-data-editor.tsx | 16 +++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/views/account-data-editor/__tests__/account-data-editor.test.tsx b/src/views/account-data-editor/__tests__/account-data-editor.test.tsx index e5e505a9..4f9ed00d 100644 --- a/src/views/account-data-editor/__tests__/account-data-editor.test.tsx +++ b/src/views/account-data-editor/__tests__/account-data-editor.test.tsx @@ -79,8 +79,20 @@ vi.mock('react-ace', async () => { }; }); -vi.mock('ace-builds/src-noconflict/mode-json', () => ({})); -vi.mock('ace-builds/src-noconflict/theme-monokai', () => ({})); +vi.mock('ace-builds/src-noconflict/mode-json', () => { + if (!(globalThis as typeof globalThis & { ace?: unknown }).ace) { + throw new Error('mode-json imported before ace'); + } + + return {}; +}); +vi.mock('ace-builds/src-noconflict/theme-monokai', () => { + if (!(globalThis as typeof globalThis & { ace?: unknown }).ace) { + throw new Error('theme-monokai imported before ace'); + } + + return {}; +}); vi.mock('ace-builds/esm-resolver', () => { if (!(globalThis as typeof globalThis & { ace?: unknown }).ace) { throw new Error('ace is not defined'); diff --git a/src/views/account-data-editor/account-data-editor.tsx b/src/views/account-data-editor/account-data-editor.tsx index c579015c..e508ee15 100644 --- a/src/views/account-data-editor/account-data-editor.tsx +++ b/src/views/account-data-editor/account-data-editor.tsx @@ -23,13 +23,15 @@ type EditorState = { }; const loadAce = async () => { - const aceModulePromise = import('react-ace'); - const workerJsonModulePromise = import('ace-builds/src-noconflict/worker-json?url'); - const modeJsonPromise = import('ace-builds/src-noconflict/mode-json'); - const themeMonokaiPromise = import('ace-builds/src-noconflict/theme-monokai'); - const resolverPromise = aceModulePromise.then(() => import('ace-builds/esm-resolver')); - const [aceModule, workerJsonModule] = await Promise.all([aceModulePromise, workerJsonModulePromise, resolverPromise, modeJsonPromise, themeMonokaiPromise]); - // esm-resolver waits for react-ace so it can see the global ace instance. + const aceModule = await import('react-ace'); + // Do not start these before react-ace resolves; Ace chunks read the global ace + // binding while evaluating and fail in production modules if they race ahead. + const [workerJsonModule] = await Promise.all([ + import('ace-builds/src-noconflict/worker-json?url'), + import('ace-builds/esm-resolver'), + import('ace-builds/src-noconflict/mode-json'), + import('ace-builds/src-noconflict/theme-monokai'), + ]); const mod = aceModule.default; const Editor = typeof mod === 'function' ? mod : (mod as unknown as { default: typeof mod }).default;