From ed5e4300e4d20a65213d0f340bb6afd425789d2d Mon Sep 17 00:00:00 2001 From: chef-ryan Date: Mon, 14 Oct 2024 11:46:13 +0800 Subject: [PATCH] fix: AbortController and AbortSignal.timeout Polyfill (#10815) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduced a polyfill for AbortController and AbortSignal.timeout, enabling support for aborting operations in environments that do not natively support these features. - This addition allows developers to use AbortController to manage request cancellations more effectively, improving error handling and resource management. --- ## PR-Codex overview This PR introduces the `abortcontroller-polyfill` to enhance compatibility with the `AbortSignal` API in the application. It also updates package dependencies and modifies the `package.json` to include the new polyfill. ### Detailed summary - Added `abortcontroller-polyfill` import in `apps/web/src/pages/_app.tsx`. - Implemented a timeout function in `apps/web/src/utils/abortcontroller-polyfill.ts`. - Updated `pnpm-lock.yaml` to include `abortcontroller-polyfill` version 1.7.5. - Updated `@noble/curves` from 1.4.0 to 1.6.0 in `pnpm-lock.yaml`. - Updated `ws` from 8.17.1 to 8.18.0 in `pnpm-lock.yaml`. - Added `@kyberswap/pancake-liquidity-widgets` version 0.1.1 to `apps/web/package.json`. - Removed `@kyberswap/pancake-liquidity-widgets` from previous dependencies in `apps/web/package.json`. - Added `abortcontroller-polyfill` version 1.7.5 to `apps/web/package.json`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- apps/web/package.json | 3 ++- apps/web/src/pages/_app.tsx | 1 + apps/web/src/utils/abortcontroller-polyfill.ts | 10 ++++++++++ pnpm-lock.yaml | 7 +++++-- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/utils/abortcontroller-polyfill.ts diff --git a/apps/web/package.json b/apps/web/package.json index c7aba570fa26f..008646987a90b 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -42,6 +42,7 @@ "@datadog/browser-rum": "^5.8.0", "@gelatonetwork/limit-orders-lib": "^4.1.0", "@gnosis.pm/safe-apps-wagmi": "^1.2.0", + "@kyberswap/pancake-liquidity-widgets": "0.1.1", "@next/bundle-analyzer": "13.0.7", "@orbs-network/twap-ui": "0.11.2", "@orbs-network/twap-ui-pancake": "0.11.2", @@ -78,7 +79,6 @@ "@pancakeswap/v3-sdk": "workspace:*", "@pancakeswap/wagmi": "workspace:*", "@pancakeswap/widgets-internal": "workspace:*", - "@kyberswap/pancake-liquidity-widgets": "0.1.1", "@pythnetwork/pyth-evm-js": "^1.29.2", "@reduxjs/toolkit": "^1.9.1", "@sentry/nextjs": "^8.16.0", @@ -92,6 +92,7 @@ "@web3inbox/core": "1.2.0", "@web3inbox/react": "1.2.0", "@yornaath/batshit": "^0.9.0", + "abortcontroller-polyfill": "1.7.5", "ajv": "^6.12.3", "bignumber.js": "^9.0.0", "bottleneck": "^2.19.5", diff --git a/apps/web/src/pages/_app.tsx b/apps/web/src/pages/_app.tsx index 13ef2e4372c5e..4af539a98e6bf 100644 --- a/apps/web/src/pages/_app.tsx +++ b/apps/web/src/pages/_app.tsx @@ -24,6 +24,7 @@ import Head from 'next/head' import Script from 'next/script' import { Fragment } from 'react' import { PersistGate } from 'redux-persist/integration/react' +import 'utils/abortcontroller-polyfill' import { V4CakeIcon } from 'views/Home/components/V4CakeIcon' import { ZKSyncAirdropModalWithAutoPopup } from 'components/ClaimZksyncAirdropModal' diff --git a/apps/web/src/utils/abortcontroller-polyfill.ts b/apps/web/src/utils/abortcontroller-polyfill.ts new file mode 100644 index 0000000000000..edfed48cfce52 --- /dev/null +++ b/apps/web/src/utils/abortcontroller-polyfill.ts @@ -0,0 +1,10 @@ +import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only' + +if (!('timeout' in AbortSignal)) { + const timeoutFN = (ms: number) => { + const controller = new AbortController() + setTimeout(() => controller.abort(), ms) + return controller.signal + } + ;(AbortSignal as any).timeout = timeoutFN +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11f66d34ae4ad..af774c7dd4f33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1067,6 +1067,9 @@ importers: '@yornaath/batshit': specifier: ^0.9.0 version: 0.9.0 + abortcontroller-polyfill: + specifier: 1.7.5 + version: 1.7.5 ajv: specifier: ^6.12.3 version: 6.12.6 @@ -23226,7 +23229,7 @@ snapshots: '@solana/web3.js@1.87.6(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.24.7 - '@noble/curves': 1.4.0 + '@noble/curves': 1.6.0 '@noble/hashes': 1.5.0 '@solana/buffer-layout': 4.0.1 agentkeepalive: 4.5.0 @@ -34843,7 +34846,7 @@ snapshots: '@babel/runtime': 7.24.7 eventemitter3: 4.0.7 uuid: 8.3.2 - ws: 8.17.1(bufferutil@4.0.8)(utf-8-validate@5.0.10) + ws: 8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) optionalDependencies: bufferutil: 4.0.8 utf-8-validate: 5.0.10