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

RenderQueue doesn't appear to be ordered by depth #874

Closed
esprehn opened this issue Sep 15, 2017 · 3 comments · Fixed by #1534
Closed

RenderQueue doesn't appear to be ordered by depth #874

esprehn opened this issue Sep 15, 2017 · 3 comments · Fixed by #1534

Comments

@esprehn
Copy link

esprehn commented Sep 15, 2017

Ideally you render top down to avoid doing wasted work on child components that a parent component is going to remove or pass different props to. It currently appears that the queue is in the order of the setState calls which means a child component might rerender and build up new dom and then a parent would render and do it again and possibly remove that child entirely or pass down different props.

https://github.com/developit/preact/blob/80ad4367e5352cbf6720f973a4488f6504498eb9/src/component.js#L58
https://github.com/developit/preact/blob/576dda310a8e31e524fa2ecc803d6d406597c41e/src/render-queue.js#L10

Instead I think you want to walk up the tree of components until you find the highest one with _dirty === true, render that and then repeat until every component is clean.

@developit
Copy link
Member

developit commented Sep 18, 2017

It's not possible to walk the resolved tree in Preact because that would require walking the DOM (prohibitively expensive in this case).

I just checked and it appears when flushing the render queue, we iterate backwards. This means the order in that queue is actually a reasonable approximation of outermost-first.

One thing that might be interesting - we're looking at adding an _ancestorComponent property to components in #819. Perhaps that could provide a means to quickly determine if child component renders are invalidated by an enqueued parent component render.

@esprehn
Copy link
Author

esprehn commented Sep 20, 2017

Can you explain why walking the dom would be too expensive?

@developit
Copy link
Member

It would invoke a huge number of DOM getters and the time required would increase as DOM size increases.

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 a pull request may close this issue.

2 participants