Problems using the compiler at Stack Auth #38
N2D4
started this conversation in
Something went wrong
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all, we're super excited for a future with the compiler, and can't wait to support Stack Auth with it.
However, in our client SDK, we have a lot of APIs that use promises. Code might look like this:
Since we target React natively, we provide hook-based counterparts:
This is a very powerful pattern. It lets us model large data structures without exposing our users to too much complexity; also, it means the hook-based SDK is consistent with the Promise-based one.
Notably, this pattern can align with the rules of React;
useConnectedAccount
is on the prototype ofUser
, just called with differentthis
arguments. We never need to actually pass the hook around as a value.Unfortunately the new React compiler's static analysis throws an error:
It's true that this could be the case (for some implementation of
useUser
), but also there's no way for us as library authors to tell the compiler that the hook is safe to call. I would say the most common case is thatuseConnectedAccount(...)
is a function on the User prototype, and that it's always the same (with differentthis
arguments).Disabling the compiler on our side is not an option; this is code that our users write, and the errors will be thrown on their side.
Beta Was this translation helpful? Give feedback.
All reactions