Emoji: Fix Web Worker import (#36603)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { initialState } from '@/mastodon/initial_state';
|
||||
import { loadWorker } from '@/mastodon/utils/workers';
|
||||
|
||||
import { toSupportedLocale } from './locale';
|
||||
import { emojiLogger } from './utils';
|
||||
// eslint-disable-next-line import/default -- Importing via worker loader.
|
||||
import EmojiWorker from './worker?worker&inline';
|
||||
|
||||
const userLocale = toSupportedLocale(initialState?.meta.locale ?? 'en');
|
||||
|
||||
@@ -16,9 +17,7 @@ export function initializeEmoji() {
|
||||
log('initializing emojis');
|
||||
if (!worker && 'Worker' in window) {
|
||||
try {
|
||||
worker = loadWorker(new URL('./worker', import.meta.url), {
|
||||
type: 'module',
|
||||
});
|
||||
worker = new EmojiWorker();
|
||||
} catch (err) {
|
||||
console.warn('Error creating web worker:', err);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// If there are no polyfills, then this is just Promise.resolve() which means
|
||||
// it will execute in the same tick of the event loop (i.e. near-instant).
|
||||
|
||||
// eslint-disable-next-line import/extensions -- This file is virtual so it thinks it has an extension
|
||||
import 'vite/modulepreload-polyfill';
|
||||
|
||||
import { loadIntlPolyfills } from './intl';
|
||||
|
||||
function importExtraPolyfills() {
|
||||
@@ -17,6 +14,7 @@ export function loadPolyfills() {
|
||||
const needsExtraPolyfills = !window.requestIdleCallback;
|
||||
|
||||
return Promise.all([
|
||||
loadVitePreloadPolyfill(),
|
||||
loadIntlPolyfills(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- those properties might not exist in old browsers, even if they are always here in types
|
||||
needsExtraPolyfills ? importExtraPolyfills() : Promise.resolve(),
|
||||
@@ -31,5 +29,13 @@ async function loadEmojiPolyfills() {
|
||||
}
|
||||
}
|
||||
|
||||
// Loads Vite's module preload polyfill for older browsers, but not in a Worker context.
|
||||
function loadVitePreloadPolyfill() {
|
||||
if (typeof document === 'undefined') return;
|
||||
// @ts-expect-error -- This is a virtual module provided by Vite.
|
||||
// eslint-disable-next-line import/extensions
|
||||
return import('vite/modulepreload-polyfill');
|
||||
}
|
||||
|
||||
// Null unless polyfill is needed.
|
||||
export let emojiRegexPolyfill: RegExp | null = null;
|
||||
|
||||
Reference in New Issue
Block a user