Skip to content

Commit bf54f25

Browse files
committed
fix: inject promise polyfill in root head
1 parent 36b5b5f commit bf54f25

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/routes/__root.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { twMerge } from 'tailwind-merge'
4242
const GOOGLE_ANALYTICS_ID = 'G-JMT1Z50SPS'
4343
const GOOGLE_ANALYTICS_SCRIPT_SRC = `https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_ID}`
4444
const GOOGLE_ANALYTICS_BOOTSTRAP = `window.dataLayer = window.dataLayer || [];window.gtag = window.gtag || function(){window.dataLayer.push(arguments);};window.gtag('js', new Date());window.gtag('config', '${GOOGLE_ANALYTICS_ID}');`
45+
const PROMISE_WITH_RESOLVERS_POLYFILL = `(function(){if(typeof Promise.withResolvers!=='function'){Object.defineProperty(Promise,'withResolvers',{configurable:true,writable:true,value:function(){var resolve,reject;var promise=new Promise(function(r,j){resolve=r;reject=j});return{promise:promise,resolve:resolve,reject:reject}}})}})()`
4546

4647
declare global {
4748
interface Window {
@@ -111,6 +112,9 @@ export const Route = createRootRouteWithContext<{
111112
{ rel: 'icon', href: '/favicon.ico' },
112113
],
113114
scripts: [
115+
{
116+
children: PROMISE_WITH_RESOLVERS_POLYFILL,
117+
},
114118
// Theme detection script - must run before body renders to prevent flash
115119
{
116120
children: `(function(){try{var t=localStorage.getItem('theme')||'auto';var v=['light','dark','auto'].includes(t)?t:'auto';if(v==='auto'){var a=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.classList.add(a,'auto')}else{document.documentElement.classList.add(v)}}catch(e){var a=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';document.documentElement.classList.add(a,'auto')}})()`,

0 commit comments

Comments
 (0)