Fix accidentally instantiating Web Worker (#35473)
This commit is contained in:
@@ -4,19 +4,27 @@ import { toSupportedLocale } from './locale';
|
||||
|
||||
const userLocale = toSupportedLocale(initialState?.meta.locale ?? 'en');
|
||||
|
||||
const worker =
|
||||
'Worker' in window
|
||||
? new Worker(new URL('./worker', import.meta.url), {
|
||||
type: 'module',
|
||||
})
|
||||
: null;
|
||||
let worker: Worker | null = null;
|
||||
|
||||
export async function initializeEmoji() {
|
||||
if (!worker && 'Worker' in window) {
|
||||
try {
|
||||
worker = new Worker(new URL('./worker', import.meta.url), {
|
||||
type: 'module',
|
||||
credentials: 'omit',
|
||||
});
|
||||
} catch (err) {
|
||||
console.warn('Error creating web worker:', err);
|
||||
}
|
||||
}
|
||||
|
||||
if (worker) {
|
||||
worker.addEventListener('message', (event: MessageEvent<string>) => {
|
||||
// Assign worker to const to make TS happy inside the event listener.
|
||||
const thisWorker = worker;
|
||||
thisWorker.addEventListener('message', (event: MessageEvent<string>) => {
|
||||
const { data: message } = event;
|
||||
if (message === 'ready') {
|
||||
worker.postMessage('custom');
|
||||
thisWorker.postMessage('custom');
|
||||
void loadEmojiLocale(userLocale);
|
||||
// Load English locale as well, because people are still used to
|
||||
// using it from before we supported other locales.
|
||||
|
||||
@@ -4,7 +4,6 @@ import EMOJI_REGEX from 'emojibase-regex/emoji-loose';
|
||||
import { autoPlayGif } from '@/mastodon/initial_state';
|
||||
import { assetHost } from '@/mastodon/utils/config';
|
||||
|
||||
import { loadEmojiLocale } from '.';
|
||||
import {
|
||||
EMOJI_MODE_NATIVE,
|
||||
EMOJI_MODE_NATIVE_WITH_FLAGS,
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
searchCustomEmojisByShortcodes,
|
||||
searchEmojisByHexcodes,
|
||||
} from './database';
|
||||
import { loadEmojiLocale } from './index';
|
||||
import {
|
||||
emojiToUnicodeHex,
|
||||
twemojiHasBorder,
|
||||
|
||||
Reference in New Issue
Block a user