mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(account-data-editor): restore Ace load ordering
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user