Recoil: Duplicate atom key warning when used from multiple bundles

Created on 31 May 2020  路  11Comments  路  Source: facebookexperimental/Recoil

For 0.0.8, I am getting the following blocking error (was working fine with 0.07):

recoil.development.js:117 Uncaught TypeError: Cannot destructure property 'error' of 'undefined' as it is undefined.

Two issues afaics:

  1. It displays the wrong error, since there isnt a third parameter in the call from registerNode:
    https://github.com/facebookexperimental/Recoil/blob/22b42bbc0366bf748b4265735eb4b6c90c90ff1f/src/core/Recoil_Node.js#L84
  2. The actual error (Duplicate atom key ..) it wants to display is not correct, since I have only one of this key registered (it is not duplicated), however the package is called from two bundles.

All 11 comments

@drarmstr thanks for linking this issue to a PR. However I also have a second part - that the error 'Duplicate atom key .' is not correct.

Should I file a new issue about that, or do you have any feedback on this?

Are you using HMR? That will trigger that error I believe.

I am using hmr however the error shows without hmr being invoked (no files are changed, just loading the app generates the error)

@atanasster I don't think we've seen the duplicate key issue outside of HMR, but it sounds like it may be due to the atom being created twice from the two bundles?

@atanasster - Please re-open this issue if you continue to see a problem without HMR.

image
Hi all, I got this warning when trying Recoil with NextJS. This happens every time I try refresh with new page.

I think it might be HMR problem because it happened on development only, but I want to know how I do a singleton pattern for atom to prevent this warning on development.

Thanks!

any news?

time to re-open the issue :/

Experiencing the same issue as @hmtri1011 described.

@hmtri1011 Any solution ?

I felt it's worth mentioning this. If you declare your atom/selector inside the same file it is being used, you will see this warning whether your have hot module replacement enabled or not. It is best to import it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ymolists picture ymolists  路  3Comments

karevn picture karevn  路  3Comments

eLeontev picture eLeontev  路  3Comments

yuantongkang picture yuantongkang  路  3Comments

ibnumusyaffa picture ibnumusyaffa  路  4Comments