diff --git a/sample/next-app/app/Sample.tsx b/sample/next-app/app/Sample.tsx index bd896b64e..080efbc91 100644 --- a/sample/next-app/app/Sample.tsx +++ b/sample/next-app/app/Sample.tsx @@ -1,5 +1,6 @@ 'use client'; +import "../utils/pdfWorkerPolyfill" import { useCallback, useState } from 'react'; import { useResizeObserver } from '@wojtekmaj/react-hooks'; import { pdfjs, Document, Page } from 'react-pdf'; diff --git a/sample/next-app/utils/pdfWorkerPolyfill.ts b/sample/next-app/utils/pdfWorkerPolyfill.ts new file mode 100644 index 000000000..01cd99e0e --- /dev/null +++ b/sample/next-app/utils/pdfWorkerPolyfill.ts @@ -0,0 +1,25 @@ +"use client"; + +if (Promise.withResolvers === undefined) { + if (typeof window !== "undefined") { + // @ts-expect-error This does not exist outside of polyfill which this is doing + window.Promise.withResolvers = function () { + let resolve, reject; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { promise, resolve, reject }; + }; + } else { + // @ts-expect-error This does not exist outside of polyfill which this is doing + global.Promise.withResolvers = function () { + let resolve, reject; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { promise, resolve, reject }; + }; + } +}