Skip to content

fetchBaseQuery with timeout breaks abort() on lazy queries #5025

@rusnick31

Description

@rusnick31
export const api = createApi({
  reducerPath: 'apiCache',
  baseQuery: fetchBaseQuery({ baseUrl: '/api/v1', timeout: 5000 }),
  endpoints: (builder) => ({
    getData: builder.query<string, void>({
      query: () => ({ url: '/data/' }),
    }),
  }),
});
const Component: FC = () => {
  const abortRef = useRef<() => void>();
  const [trigger] = useLazyGetDataQuery();

  return (
    <div>
      <input
        onChange={() => {
          abortRef.current?.();
          const result = trigger();
          abortRef.current = () => {
            result.abort();
          };
        }}
      />
    </div>
  );
};

when I pass a timeout option to fetchBaseQuery, the abort() function returned by a lazy query stops working and throws the following error:

Image

Without timeout everything works as intended

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions