[BUG] config() race condition related to top-levelsetChainIdDefault()
call
#1641
Labels
Bug
Something isn't working
setChainIdDefault()
call
#1641
Current Behavior
This "issue" is a bit trivial since it affect end behaviour, but... If you are to run the following code you will notice a bunch of console errors.
However, if you run this code, you will notice no errors appear.
This is because we have a race condition. (i.e. if we are not to set the configuration until the call stack/job queue has emptied, we will see this error). This becomes an issue in something like a react app where we configure fcl in a
useEffect
hook which is not run immediately.The specific culprit is this line of code which runs at the top-level (thus right when fcl loads).
fcl-js/packages/fcl/src/default-config.js
Line 19 in 2e5ca45
While this bug exists, it does not affect app behaviour because ultimately the
chainId
is always accessed throughgetChainId()
within fcl & in this function the chain ID is always resolved if it doesn't know it already.fcl-js/packages/fcl/src/utils/getChainId.js
Line 37 in 2e5ca45
However, the error can throw developers off, so it is probably best to get rid of.
Expected Behavior
Don't show this error at startup if config hasn't been set 😎.
I suggest one of the following:
setChainIdDefault
of whetherconfig.get("accessNode.api")
is defined, don't attempt to resolve chainId if it has not been (still imperfect, basically as performant as soln. 1 unless user configures fcl @ top level)accessNode.api
change or even just any config change is good enough. (this would be ideal solution)Steps To Reproduce
Shown above.
Environment
What are you currently working on that this is blocking?
Nothing. Bug does not affect application behaviour.
The text was updated successfully, but these errors were encountered: