-
Notifications
You must be signed in to change notification settings - Fork 49.7k
Update Dirty Components in Mount Ordering #2367
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
Conversation
Summary: Currently, `ReactUpdates` updates dirty components in increasing order of mount depth. However, mount depth is only relative to the component passed into `React.render`. This breaks down for components that invoke `React.render` as an implementation detail because the child components will be updated before the parent component. This fixes the problem by using the order in which components are mounted (instead of their depth). The mount order transcends component trees (rooted at `React.render` calls). Test Plan: Ran unit tests successfully: ``` npm run jest ```
|
#1853 related? (components are notified of unmount in reverse order) |
|
A few things stand out for me;
|
Relying on Due to the way that |
I see what you're saying about render trees now. But, technically, this is only a partial solution then. If we consider that Hmm, could we not assign each render tree an order/depth instead and sort by: parent tree depth/order > component mount depth. Then we get the necessary render tree ordering. We could then also recompute the render tree order/depth each render (traverse the DOM parents, should be cheap) then we're guaranteed to always apply them in the correct order, but that could simply be forbidden I guess (and cross render tree component reparenting doesn't sound sane). EDIT: The upside to sorting only by render tree depth/order is that we could use radix sort and make it EDIT: All things said, your solution does make a lot of sense seing as there's no obvious golden ticket. |
|
This is a very interesting artifact you've found. I like it. The only issue is that this algorithm doesn't parallelize well but I guess it can be bucketed. Can we get a unit test of a use case which this fixes? Reconciliation order isn't part of the public contract because they're expected to be side-effect free but I'm guessing that something is incorrect without this fix? Or is it just a perf optimization? If so, the test should test that. I suspect that this solution is incomplete since we don't treat rerenders as part of a subtree. E.g. events don't propagate etc. What other bugs could there be remaining? |
|
This was accidentally closed because the branch is gone. However, the assumption will also start breaking down since with this feature: Children can be mounted before their parents. This won't really affect new render roots but everything up to that point.
|
|
Yup, sorry I am a n00b at GitHub. It's back up here: #2570 |
Summary:
Currently,
ReactUpdatesupdates dirty components in increasing order of mount depth. However, mount depth is only relative to the component passed intoReact.render. This breaks down for components that invokeReact.renderas an implementation detail because the child components will be updated before the parent component.This fixes the problem by using the order in which components are mounted (instead of their depth). The mount order transcends component trees (rooted at
React.rendercalls).Reviewers: @sebmarkbage @zpao
Test Plan:
Ran unit tests successfully: