-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Component state leakage #413
Comments
Seems crazy this didn't come up before - maybe it's a regression? What version of preact by the way? |
"preact": "7.0.3", |
I was able to reproduce it with console.log(this.state) // <-- null I think the reason why it didn't come up earlier was the missing state initialization, because you usually initialize the state in the constructor or in the class property: class Parent extends Component {
state = {} // <-- it works fine, because the default state object is replaced
componentDidMount() {
this.setState({FUBAR: true})
}
render() {
return this.props.children
}
}
class Child extends Component {
render() {
console.log(this.state) // <-- ok, returns {}
return null
}
} P.S. btw, I'm not sure if it's ok to return |
Is it possible this is related to preact-compat? Which |
Hm, it could be, I'm using |
Ah ok I will scour that repo for a cause. |
Do you need a repo to reproduce this issue? |
I'm using this: https://jsfiddle.net/developit/rojcvahn/ |
Can confirm, this only happens in preact-compat. |
Same problem here. Surely a preact-compat issue. And its going right into 2nd level 😄 In my case case its getting trasferred to a new page. |
Alright, let's prioritize this then, it's just too strange to leave open. |
working great 👍 |
I found an issue with the state of a component in preact, for example:
As you can see,
Parent
leaks its state toChild
because the default state object is reused across all components.The text was updated successfully, but these errors were encountered: