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 nested pure components #1301

Merged
merged 5 commits into from
Apr 18, 2022
Merged

Conversation

nicksenger
Copy link
Contributor

@nicksenger nicksenger commented Apr 6, 2022

Currently, using a pure component within another pure component will cause the application to panic in certain cases. As far as I can tell, this is because the creation of a component's element is deferred until diff is called on the corresponding widget tree, which may not happen before on_event if that component is nested within another component which undergoes some internal state change.

Repro case here: https://gist.github.com/nicksenger/543e1574b4a5519d9775e94359ae66eb

Diffing the widget tree after processing local events rebuilds the element for any sub-components, which resolves the issue.

@nicksenger
Copy link
Contributor Author

Going to go ahead and open this up. I've tested it pretty extensively at this point and it seems to be working as intended.

@nicksenger nicksenger marked this pull request as ready for review April 12, 2022 19:08
@nicksenger
Copy link
Contributor Author

It seems the fix for this is much more straightforward than I previously thought. We simply need to diff the widget tree after rebuilding the cached element in on_event.

Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! That makes way more sense 🎉

Thank you!

@hecrj hecrj added bug Something isn't working widget labels Apr 18, 2022
@hecrj hecrj added this to the 0.4.0 milestone Apr 18, 2022
@hecrj hecrj merged commit 26b68d7 into iced-rs:master Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants