Skip to content

Remove nanoid #1712

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

Closed
1 task done
imranbarbhuiya opened this issue Jun 20, 2024 · 6 comments
Closed
1 task done

Remove nanoid #1712

imranbarbhuiya opened this issue Jun 20, 2024 · 6 comments
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@imranbarbhuiya
Copy link

Description
A brief description of the bug. Provide either a screenshot or the full error message

Hi, thanks for this awesome lib, the new version added nanoid for middleware usage, I'm using this package in my rn project and crypto isn't available there. Not only rn but there's other platforms/runtimes too where crypto available so adding that to dep and using it even when we arent using middleware makes it impossible for me to update. For now, I patched the package to remove nanoid. I can create a pr to fix it but need to discuss what should we use instead.

Reproduction
How can this be reproduced / when did the error occur? Does the issue occur in a specific browser, or all browsers?
Use the package in any env where crypto isn't available

Expected result
It should work and specially when I'm not even using middleware so id is useless for me.
(in case it’s not obvious)

Checklist

@imranbarbhuiya imranbarbhuiya added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jun 20, 2024
@drwpow
Copy link
Contributor

drwpow commented Jun 20, 2024

I’m not particular about the library used; it’s swappable. Actually looking at benchmarks I would like to use something faster, but without incurring the full weight of uuid. I may even end up handrolling something because it doesn’t need to be secure, or that unique (it can collide much more often because it’s only meant to compare requests right next to each other, not months apart)

@imranbarbhuiya
Copy link
Author

can we use simple Math.random().toString(36).slice(2, 11)?

@drwpow
Copy link
Contributor

drwpow commented Jun 21, 2024

can we use simple Math.random().toString(36).slice(2, 11)?

That’s not a bad suggestion! Though this is something I do want to split hairs on to at least match nanoid’s performance and ideally beat if possible. For many libraries that’s overkill, but a design decision of this library is to be at the center of every fetch request it should be functionally equivalent to native fetch() and be as thin and performant as absolutely possible. So microoptimizations are important here IMO.

@imranbarbhuiya
Copy link
Author

we should also need to skip generating the id when no middleware is registered

@drwpow drwpow mentioned this issue Jun 21, 2024
3 tasks
@drwpow
Copy link
Contributor

drwpow commented Jun 21, 2024

Fixed in 0.10.1. Also @imranbarbhuiya took both your suggestions, thank you! 🙂 The code provided is suitable for our purposes and sufficiently fast/minimal (it doesn’t need to be cryptographically-secure, and collisions don’t have to be super-unlikely either).

@drwpow drwpow closed this as completed Jun 21, 2024
@imranbarbhuiya
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

2 participants