diff --git a/apps/remix/app/entry.client.tsx b/apps/remix/app/entry.client.tsx index 4b5769ff5..c32cdc4e1 100644 --- a/apps/remix/app/entry.client.tsx +++ b/apps/remix/app/entry.client.tsx @@ -10,6 +10,8 @@ import { HydratedRouter } from 'react-router/dom'; import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags'; import { dynamicActivate } from '@documenso/lib/utils/i18n'; +import './utils/polyfills/promise-with-resolvers'; + function PosthogInit() { const postHogConfig = extractPostHogConfig(); diff --git a/apps/remix/app/utils/polyfills/promise-with-resolvers.ts b/apps/remix/app/utils/polyfills/promise-with-resolvers.ts new file mode 100644 index 000000000..4f34dd67a --- /dev/null +++ b/apps/remix/app/utils/polyfills/promise-with-resolvers.ts @@ -0,0 +1,30 @@ +/** + * Polyfill for Promise.withResolvers (ES2024) + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers + */ + +type PromiseWithResolvers = { + promise: Promise; + resolve: (value: T | PromiseLike) => void; + reject: (reason?: unknown) => void; +}; + +// We're patching here +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const GlobalPromise = globalThis.Promise as any; + +if (typeof GlobalPromise.withResolvers !== 'function') { + GlobalPromise.withResolvers = function (): PromiseWithResolvers { + let resolve!: (value: T | PromiseLike) => void; + let reject!: (reason?: unknown) => void; + + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + + return { promise, resolve, reject }; + }; +} + +export {};