webauthn-local-client icon indicating copy to clipboard operation
webauthn-local-client copied to clipboard

Remove top-level awaits

Open jscheid opened this issue 1 year ago • 1 comments

Is there any chance the top-level awaits could be moved into functions? That way the consumer of the library can choose when to run the code (if at all), also it makes the library compatible with older bundlers.

jscheid avatar May 15 '24 05:05 jscheid

my problem with this is, there's a reduced DX when:

  1. it's a footgun that these functions will return promises (because the underlying checks have to be asynchronous), which are truthy... so people might accidentally see the truthy promise value and not realize they need to await it before knowing if the library is supported.

  2. what's exposed are functions that only ever need to be called once, instead of just exposing the result of these calls (booleans)... sure you can cache the result internally, but it still sucks that you continue to be presented with a function call (that's promise returning!) even when on the second call it knows the answer already.

  3. the main reason for checking for support of WebAuthn capability is critical path stuff like loading alternate/fallback functionality, including rendering different controls to users, etc -- you can't do anything useful until you know the result, so why force you to wait for that result.

these concerns are why I went with top-level await. but I acknowledge that it definitely has its tradeoffs when it comes to bundlers.

getify avatar Jun 04 '24 17:06 getify

Not planned at the moment.

getify avatar Aug 30 '24 18:08 getify