-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix provider global clenup on error #89
Conversation
const { rerender } = render(<App />); | ||
rerender(<App />); | ||
|
||
expect(children.mock.calls[0][0]).toBe(children.mock.calls[1][0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an interesting test, look like there is a story behind it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because context provider memo can be fiddly 😅
} | ||
|
||
componentWillUnmount() { | ||
globalDi._remove(this.props.use); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are not the same use
you've got during the initial render and later used for _fromProvider
, these are different.
There were a few bugs due to mismatches of this sort, I would better remeber a "cleanup callback" somewhere in getValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come? I would expect them to be consistent 🤔 Unless someone decides to conditionally add/remove injectables (which we call out as not supported) it should contain the same "stuff"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, stuff happens.
This is not a real problem, but a potential.
Ideally just expose another (secret) method to check if global DI is clear. Then we can call it before test to verify that everything is as it should be. Later we can remove this method.
Well, it should be fine, but we all know that our assumptions are not always true
|
||
componentDidCatch(err) { | ||
globalDi._remove(this.props.use); | ||
throw err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double check - :notsureif: unmount not happens during catch.
I have a very string dejavu feeling right now, like we had this conversation already...
I just cannot imagine that some allocated resources (any) can be "not freed" in case of emergency. That would like a disaster!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not, just tested: neither useEffects
cleanup nor componentWillUnmount
will fire if a child throws during render (just checked). 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something we need to clarify for ourselves
Closes #88