Dash doesn't support areEqual() in React.memo() to judge wheather need to redraw
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
When I was developing the Dash component with React functional component, I found areEqual() doesn't work when I use React.memo(Component, [areEqual(prevProps, nextProps)]) to prevent some unnecessary redraw, in fact, once I set my areEqual() in React.memo(), the Dash component won't generateted success after build, here is a simple demo(Dash version: 2.6.1):
import { memo } from 'react';
const MemoDemo = (props) => {
const {
n_clicks_a,
n_clicks_b,
setProps
} = props;
return (
<div >
<button onClick={() => setProps({ n_clicks_a: n_clicks_a + 1 })}>{'button a'}</button>
<button onClick={() => setProps({ n_clicks_b: n_clicks_b + 1 })}>{'button b'}</button>
<span >
{`n_clicks_a: ${n_clicks_a} n_clicks_b: ${n_clicks_b}`}
</span>
</div>
);
}
MemoDemo.propTypes = {
id: PropTypes.string,
style: PropTypes.object,
className: PropTypes.string,
// should trigger redraw
n_clicks_a: PropTypes.number,
// should not trigger redraw
n_clicks_b: PropTypes.number,
setProps: PropTypes.func
};
MemoDemo.defaultProps = {
n_clicks_a: 0,
n_clicks_b: 0
}
export default memo(MemoDemo, (prevProps, nextProps) => {
if (prevProps.n_clicks_a === nextProps.n_clicks_a) {
// should not redraw
return true;
}
// should redraw
return false;
});
@T4rk1n
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided React.memo component example with Dash 2.6.1 and inspect the React component build path involved in generating Dash components. Confirm how the areEqual comparator is handled during the build, then verify that a component using it builds successfully and that redraw behavior follows the comparator.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100