fix: polyfill promise.withResolvers (#2282)

Co-authored-by: Catalin Pit <catalinpit@gmail.com>
This commit is contained in:
Lucas Smith
2025-12-04 23:33:31 +11:00
committed by GitHub
parent c4f89a87a2
commit 31ba6d5f00
2 changed files with 32 additions and 0 deletions
+2
View File
@@ -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();
@@ -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<T> = {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => 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 <T>(): PromiseWithResolvers<T> {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: unknown) => void;
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
};
}
export {};