question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Split <App> component to move away from shouldComponentUpdate hacks

See original GitHub issue

UPDATE: this was temporarily fixed in #593, but long-term fix is to probably split <App/> into UI and canvas components.

What’s the problem? We don’t want certain state updates to rerender the UI, only the canvas. Currently, we achieve this by preventing the <App/> component update in shouldComponentUpdate, but manually invoking this.componentDidUpdate (for side effects — scene re-render etc.), which would still have access to previous state if we didn’t manually set this.state = nextState before invoking it. This is a hack, and we should move away from this because it may have unintended consequences in the long term.


OLD:

#574 prevents component update even when internal state (appState) did in fact change (such as during scrolling), while at the same time we manually invoke componentDidUpdate for side effects. But this means that the componentDidUpdate still has access to previous state, which results in at least one bug: the scroll is not updated on the same state update.

https://github.com/excalidraw/excalidraw/blob/a862d12ac14c85177a3c78b9e4a0068bebc88179/src/index.tsx#L229-L233

We could add another hack to that, and that is to invoke this.componentDidUpdate in a setTimeout, but I’m not sure if that’s foolproof (I’m not sure when exactly the state is updated. Immediately after shouldComponentUpdate?).

Probably a better way is to separate <App/> component into two compos. One for UI, one for canvas, and prevent the update only for the UI compo.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dwellecommented, Jan 28, 2020

Yea, but if we keep both compos in index.tsx, we don’t need even that.

0reactions
vjeuxcommented, Jan 31, 2020

Feel free to do it after you land the multi arrow 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 tips for better React performance | by Aggelos Arvanitakis
In this article I will try and list out a few easy ways to achieve better performance in your React app through simple...
Read more >
How to greatly improve your React app performance - Medium
The component lifecycle hook shouldComponentUpdate is meant to prevent unnecessary renders. shouldComponentUpdate gets the next props and state ...
Read more >
10 Ways to Optimize Your React App's Performance
Here, I'll review the features and tricks that will help you optimize your app's performance. Regardless of the specific patterns and ...
Read more >
React like hook shouldComponentUpdate for Vue lifecycle ...
I think it would be useful to have a hook like React's shouldComponentUpdate in the Vue lifecycle. The idea behind this hook would...
Read more >
7 hacks to optimize your react app - DEV Community ‍ ‍
The major difference between React.Component class and React.PureComponent is the implementation of shouldComponentUpdate(). In React.Component ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found