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

renderLayer called on _every_ update? #17

Open
lydell opened this issue Mar 3, 2019 · 4 comments
Open

renderLayer called on _every_ update? #17

lydell opened this issue Mar 3, 2019 · 4 comments

Comments

@lydell
Copy link

lydell commented Mar 3, 2019

The point of <Portal> is to pass children to it (that are rendered somewhere else). And props.children !== prevProps.children always, right? If so, doesn't this mean that the for-if check in componentDidUpdate always triggers?

componentDidUpdate(props) {
for (let i in props) {
if (props[i]!==this.props[i]) {
return setTimeout(this.renderLayer);
}
}
}

@developit
Copy link
Owner

developit commented Mar 11, 2019

This is true of any Preact/react component. Update Cascade can be mitigated using shouldComponentUpdate or memo.

Fwiw the render() call diffs, so what's happening here isn't necessarily a DOM mutation, but rather the flow of data through the virtual DOM tree.

@lydell
Copy link
Author

lydell commented Mar 11, 2019

Ok! But the for-if loop does not do anything here, right? So it could be removed?

 componentDidUpdate(props) { 
 	return setTimeout(this.renderLayer); 
} 

@developit
Copy link
Owner

Technically it's possible to avoid triggering rerenders by hoisting things out of render:

const myPortal = <Portal into="body"><SomeComponent /></Portal>

class Outer {
  render() {
    return <div>{myPortal}</div>
  }
}

@lydell
Copy link
Author

lydell commented Mar 12, 2019

Thanks for the suggestion! I'm not having a performance problem or anything though, I'm just trying to understand how these things work:

Here's a codesandbox showing what I mean: https://codesandbox.io/s/k54oz8mzm3?fontsize=14

I the demo, the <Portally> component always says that props.children change (even though they don't really, kind of).

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