question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When a node rerenders due to new context api update, its siblings rerender

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Nodes that use new context api force siblings nodes to rerender

What is the expected behavior?

Siblings should not rererender when a node updates due to context updates

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

16.3.1

Background:

i use react-navigation with react-native. react-navigation uses the new context-api. withNavigationFocus-HOC wraps the component with a NavigationConsumer, a context consumer.

In this example i get unexpected rerenders:

const SomethingThatHasNavigation = withNavigationFocus(
  class extends React.Component {
    render() { 
      // i should rerender whenever navigation changes. That's fine. Its value is from context
      return null
    }
  },
)

const ShouldNotRerender = class extends React.Component {
  render() {
    console.log('i should not rerender when my sibiling updates')
    return null
  }
}

const Test = class extends React.PureComponent {
  render() {
    console.log('test renders once')
    return (
      <View>
        <SomethingThatHasNavigation />
        <ShouldNotRerender />
      </View>
    )
  }
}

What’s wrong? is this by design?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Jun 22, 2018

I think the fix would be in 0.56.

0reactions
jacobpdqcommented, Jul 16, 2018

I’m running 16.4.

I have two independent dom nodes, far off from each other and not children/parents of either - not even siblings in a parent.

Any update to one forces an update to another, leading me to believe this feature is a singleton for a global context. Please advise @gaearon

Read more comments on GitHub >

github_iconTop Results From Across the Web

When does React re-render components? - Felix Gerschau
When the VDOM gets updated, React compares it to to a previous snapshot of the VDOM and then only updates what has changed...
Read more >
Rerendering of one sibling component due to data update in ...
Now I have another api call (update request) on button click in Index.tsx file. This update request changes data in the layout's sidebar ......
Read more >
How did I re-render: Sharing State through React-Context
It is a common pattern to “lift the state” up the component tree to a “Least-Common Ancestor” React Component if a state is...
Read more >
React Context: Why am I getting unnecessary re-renders?
Every time React detects a change to something inside its context, it triggers a re-render on all of the context subscribers so that...
Read more >
React key attribute: best practices for performant lists
update items that existed “before” and continue to exist “after” (i.e. re-render them). It's much easier to understand when you play with code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found