Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 26, 2024

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
1 check passed
@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