Matt Jankowski f204f01a23 [Glitch] Update vite to version 8.0.5
Port 4299e33389c3e6d4b229c7bc25510d4abe779e97 to glitch-soc

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2026-04-08 19:58:32 +02:00

41 lines
1.4 KiB
TypeScript

// Convenience function to load polyfills and return a promise when it's done.
// 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).
import { loadIntlPolyfills } from './intl';
function importExtraPolyfills() {
return import('./extra_polyfills');
}
export function loadPolyfills() {
// Safari does not have requestIdleCallback.
// This avoids shipping them all the polyfills.
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(),
loadEmojiPolyfills(),
]);
}
// In the case of no /v support, rely on the emojibase data.
async function loadEmojiPolyfills() {
if (!('unicodeSets' in RegExp.prototype)) {
emojiRegexPolyfill = (await import('emojibase-regex/emoji')).default;
}
}
// Loads Vite's module preload polyfill for older browsers, but not in a Worker context.
function loadVitePreloadPolyfill() {
if (typeof document === 'undefined') return;
// eslint-disable-next-line import/extensions
return import('vite/modulepreload-polyfill');
}
// Null unless polyfill is needed.
export let emojiRegexPolyfill: RegExp | null = null;