Skip to content
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

Warn or throw error when signal.value is read untracked during component render #75

Open
justjake opened this issue Apr 25, 2023 · 1 comment

Comments

@justjake
Copy link

Currently users can write a function component that looks like this, that appears to work on first render or if a parent subscribes to an atom, but actually isn't reactive to atom changes. The example comes from Discord:

const Prova = ({name}: {name: Atom<string>})=>{
  return <>
  <input type="text" value={name.value} onChange={(e)=>name.set(e.target.value)}/>
  <div>Your name is {name.value}</div>
  </>
}

Signia and/or Signia-react should either log a warning or throw an error if a component reads an atom during render in a non-reactive way. Starbeam implements this by checking React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current, which is only set when in development versions of React.

In Notion's internal state management system, we throw an error when this happens.

@ds300
Copy link
Contributor

ds300 commented Apr 27, 2023

Yeah this feels like it could save a lot of frustration! I'm down for adding a console.warn, maybe with an option to turn it into a thrown error if folks wanna get strict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants