Skip to content

React Native RTQ Query DOMException error #5160

@w3di

Description

@w3di

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

#5150

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;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    React-NativeIndicates an issue specific to the React Native environment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions