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.

Component state leakage

See original GitHub issue

I found an issue with the state of a component in preact, for example:

render(
    <Parent>
        <Child />
    </Parent>,
    document.body
)

class Parent extends Component {
     componentDidMount() {
          this.setState({FUBAR: true})
     }

     render() {
         return this.props.children
     }
}

class Child extends Component {
     render() {
         console.log(this.state) // <-- {FUBAR: true}, not undefined or {}
         return null
     }
}

As you can see, Parent leaks its state to Child because the default state object is reused across all components.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ritz078commented, Jan 29, 2017

working great 👍

0reactions
developitcommented, Jan 24, 2017

Alright, let’s prioritize this then, it’s just too strange to leave open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leakage (electronics) - Wikipedia
In electronics, leakage is the gradual transfer of electrical energy across a boundary normally viewed as insulating, such as the spontaneous discharge of...
Read more >
State leaking between React sibling components
I'm having an issue with React passing state between sibling components when one of the siblings is deleted. In my program, each component ......
Read more >
React State Update Memory Leak - Dev Genius
I've outlined one solution to a component trying to update its state once its been unmounted. This works if you're using lifecycle methods...
Read more >
How to fix the React memory leak warning - DEV Community ‍ ‍
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >
Avoid Memory Leak With React SetState On An Unmounted ...
In this post I'll show some possible workarounds for avoiding memory leaks with data fetching.
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