diff --git a/app/javascript/mastodon/features/alt_text_modal/index.tsx b/app/javascript/mastodon/features/alt_text_modal/index.tsx index 773170eaa8..c8002a81cc 100644 --- a/app/javascript/mastodon/features/alt_text_modal/index.tsx +++ b/app/javascript/mastodon/features/alt_text_modal/index.tsx @@ -15,10 +15,6 @@ import type { List as ImmutableList, Map as ImmutableMap } from 'immutable'; import { useSpring, animated } from '@react-spring/web'; import Textarea from 'react-textarea-autosize'; import { length } from 'stringz'; -// eslint-disable-next-line import/extensions -import tesseractWorkerPath from 'tesseract.js/dist/worker.min.js?url'; -// eslint-disable-next-line import/no-extraneous-dependencies -import tesseractCorePath from 'tesseract.js-core/tesseract-core.wasm.js?url'; import { showAlertForError } from 'mastodon/actions/alerts'; import { uploadThumbnail } from 'mastodon/actions/compose'; @@ -350,9 +346,15 @@ export const AltTextModal = forwardRef>( fetchTesseract() .then(async ({ createWorker }) => { + const [tesseractWorkerPath, tesseractCorePath] = await Promise.all([ + // eslint-disable-next-line import/extensions + import('tesseract.js/dist/worker.min.js?url'), + // eslint-disable-next-line import/no-extraneous-dependencies + import('tesseract.js-core/tesseract-core.wasm.js?url'), + ]); const worker = await createWorker('eng', 1, { - workerPath: tesseractWorkerPath, - corePath: tesseractCorePath, + workerPath: tesseractWorkerPath.default, + corePath: tesseractCorePath.default, langPath: `${assetHost}/ocr/lang-data`, cacheMethod: 'write', }); diff --git a/vite.config.mts b/vite.config.mts index 93631f9094..4060128305 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -131,6 +131,7 @@ const config: UserConfigFnPromise = async ({ mode }) => { 'extra_polyfills-*.js', 'polyfill-force-*.js', 'assets/mailer-*.{js,css}', + '**/*tesseract*', ], maximumFileSizeToCacheInBytes: 2 * 1_024 * 1_024, // 2 MiB },