digidem / react-dimensions

[Looking for maintainers]

Home Page:http://lab.digital-democracy.org/react-dimensions/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple listeners on window will cause performance issues

timkindberg opened this issue · comments

We are anticipating an issue where having multiple components wrapped with Dimensions will start to cause performance issues. We should consider refactoring so that there is a single 'resize' event listener on window that triggers all Dimension-wrapped components to update their dimensions.

Would you accept a pull request if we had time to work on this? Also would you have time to work on this soon?

It would be important to test whether this is actually a performance issue first. Updates already get queued up in a single animation frame update. I don't think firing window.onresize has any performance implications e.g. Firing it once vs firing 10 times won't gain anything compared with the repaint cost. Also, from an app design perspective, if possible it would make more sense to wrap an outer component in react-dimensions and pass down the props and calculate widths and heights from them. There is only one browser window so you only need those values once and everything else can be calculated.

Ah I see... I didn't realize it was essentially batched. Now I see it here: https://github.com/digidem/react-dimensions/blob/master/index.jsx#L105-L111

Nevermind then. If we notice a problem we will reopen.