Skip to content

useFetch, useCachedPromise: Fix crash when passing an argument of type URLSearchParams as an option#38

Merged
sxn merged 1 commit intomainfrom
urlsearchparams-fix
Jul 26, 2024
Merged

useFetch, useCachedPromise: Fix crash when passing an argument of type URLSearchParams as an option#38
sxn merged 1 commit intomainfrom
urlsearchparams-fix

Conversation

@sxn
Copy link
Contributor

@sxn sxn commented Jul 26, 2024

Repro:

import { List } from "@raycast/api";
import { useFetch } from "@raycast/utils";

const body = new URLSearchParams("PckStatus=Transito");

export default function Command() {
  const { isLoading, data } = useFetch("https://web.sendit.com.py/mi_cuenta/get_packages_micuenta", {
    method: "POST",
    body,
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    parseResponse: (response) => response.json() as Promise<Response>,
  });

  return <List></List>
}

image

After a little digging, it seems hash doesn't support URLSearchParams, so it throws an exception, crashing the command.

This PR wraps objectHash, adding a custom replacer that stringifies args of type URLSearchParams.

@sxn sxn merged commit 0458341 into main Jul 26, 2024
@sxn sxn deleted the urlsearchparams-fix branch July 26, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant