Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

[Hooks] Highlight Updates incorrectly reports an updates in a tree component #1216

Closed
@taras

Description

@taras

I'm creating a demo of stability of Microstates trees. My goal was to show that Microstates re-uses references between transitions allowing caching of trees of children based on reference to a microstate.

function FamilyTree({ person }) {
  let name = useMemo(
    () => {
      console.log('Updating name to', person.name.state);
      return (
        <input
          value={person.name.state}
          onChange={e => person.name.set(e.target.value)}
        />
      );
    },
    [person.name]
  );

  let father = useMemo(() => <FamilyTree person={person.father} />, [
    person.father
  ]);

  let mother = useMemo(() => <FamilyTree person={person.mother} />, [
    person.mother
  ]);

  return (
    <>
      {name}
      {person.name.state && (
        <ul>
          <li>Father: {father}</li>
          <li>Mother: {mother}</li>
        </ul>
      )}
    </>
  );
}

In this example, I'm memoizing children based on references to microstates in person microstate. I added a console log to log when an input is being re-rendered. Here is a screen recording of this in action.

2018-11-04 09 39 28

To reproduce this:

  1. Create a sandbox with the demo app
  2. Open the apps live url in the browser
  3. Open React Devtools and activate "Highlight Updates"
  4. Enter names a few level deep

I would expect to only see the input that I'm highlighting update, but it's showing that parent's input fields are updating as well. The console log shows that only one input is being updated when an input is changed. I suspect that it's highlighting parent elements where children are changing, but I wouldn't expect this to be visible.

Here is the demo code https://github.com/taras/microstates-use-state

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions