Skip to content
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

Merged
merged 3 commits into from
Jan 5, 2024
Merged

Conversation

albertogasparin
Copy link
Owner

@albertogasparin albertogasparin commented Jan 4, 2024

Closes #88

const { rerender } = render(<App />);
rerender(<App />);

expect(children.mock.calls[0][0]).toBe(children.mock.calls[1][0]);
Copy link
Collaborator

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.

Copy link
Owner Author

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);
Copy link
Collaborator

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

Copy link
Owner Author

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"

Copy link
Collaborator

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;
Copy link
Collaborator

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!

Copy link
Owner Author

@albertogasparin albertogasparin Jan 5, 2024

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). 😢

Copy link
Collaborator

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

@albertogasparin albertogasparin merged commit 2c2adf7 into master Jan 5, 2024
1 check passed
@albertogasparin albertogasparin deleted the fix/provider-throw branch January 5, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DiProvider with global does not clean replacementMap on error
2 participants