Skip to content

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

@justjake

Description

@justjake

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions