-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
In the new version of Redux Toolkit (after PR #5150 "Tweaks to AbortSignal logic"), timeout handling changed: instead of manual logic, they now use DOMException with the name 'TimeoutError'. In timeoutSignal, they now call new DOMException('', 'TimeoutError') to abort requests.
The issue is that DOMException is a browser API that doesn't exist in React Native. When RTK Query tries to create new DOMException('', 'TimeoutError') on timeout, the app crashes with ReferenceError: Property 'DOMException' doesn't exist. I fixed this by creating a polyfill for DOMException, but I don't think this was the intended behavior of the update.
https://github.com/reduxjs/redux-toolkit/releases/tag/v2.11.1
my temporary solution for the project:
if (typeof globalThis.DOMException === 'undefined') {
class DOMExceptionPolyfill extends Error {
name: string;
constructor(message = '', name = 'Error') {
super(message);
this.name = name;
this.message = message;
Object.setPrototypeOf(this, DOMExceptionPolyfill.prototype);
}
}
globalThis.DOMException = DOMExceptionPolyfill;
if (typeof global !== 'undefined') {
global.DOMException = DOMExceptionPolyfill;
}
}