2
0

Emoji: Fix Web Worker import (#36603)

This commit is contained in:
Echo
2025-10-27 18:36:01 +01:00
committed by GitHub
parent 76053fb4a9
commit d0d09fd3a5
2 changed files with 12 additions and 7 deletions

View File

@@ -1,8 +1,9 @@
import { initialState } from '@/mastodon/initial_state'; import { initialState } from '@/mastodon/initial_state';
import { loadWorker } from '@/mastodon/utils/workers';
import { toSupportedLocale } from './locale'; import { toSupportedLocale } from './locale';
import { emojiLogger } from './utils'; 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'); const userLocale = toSupportedLocale(initialState?.meta.locale ?? 'en');
@@ -16,9 +17,7 @@ export function initializeEmoji() {
log('initializing emojis'); log('initializing emojis');
if (!worker && 'Worker' in window) { if (!worker && 'Worker' in window) {
try { try {
worker = loadWorker(new URL('./worker', import.meta.url), { worker = new EmojiWorker();
type: 'module',
});
} catch (err) { } catch (err) {
console.warn('Error creating web worker:', err); console.warn('Error creating web worker:', err);
} }

View File

@@ -2,9 +2,6 @@
// If there are no polyfills, then this is just Promise.resolve() which means // 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). // 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'; import { loadIntlPolyfills } from './intl';
function importExtraPolyfills() { function importExtraPolyfills() {
@@ -17,6 +14,7 @@ export function loadPolyfills() {
const needsExtraPolyfills = !window.requestIdleCallback; const needsExtraPolyfills = !window.requestIdleCallback;
return Promise.all([ return Promise.all([
loadVitePreloadPolyfill(),
loadIntlPolyfills(), 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 // 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(), 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. // Null unless polyfill is needed.
export let emojiRegexPolyfill: RegExp | null = null; export let emojiRegexPolyfill: RegExp | null = null;