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

Render from the topmost dirty component downward #38

Open
joshaber opened this issue Mar 22, 2015 · 1 comment
Open

Render from the topmost dirty component downward #38

joshaber opened this issue Mar 22, 2015 · 1 comment

Comments

@joshaber
Copy link
Owner

Currently each component re-renders itself when its state changes. This works, but it's less than ideal.

Consider a component A which renders a component B. If both update their state in the same runloop, component B will be rendered twice: once by itself because of its state update, and once when component A re-renders itself.

We should start each re-render from the topmost dirty component.

(I don't think there are any correctness problems here, but it's certainly less performant.)

@mrjjwright
Copy link

Yeah I noticed this. Each Component enqueues a render when it's state changes and is adding a separate render run loop handler. React handles this via keeping tracking of a component's owner. React distinguishes a component's owner versus it's parent. Each component can have only one owner of course, the react component that gave it it's properties. There is a single global ReactCurrentOwner.owner property that is set at the beginning of a render and represents the current owner of any elements under construction in the render. If another render is called again when a render is in place (distinguished by ReactCurrentOwner.owner != null) a warning is thrown in dev mode. At the end of the render it is set back to null. See: https://github.com/facebook/react/blob/master/src/core/ReactCompositeComponent.js#L784. You probably already knew this but I used this as an excuse to learn more.

In a parallel native environment you probably don't want to use the global flag.

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

No branches or pull requests

2 participants