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.

Side effects in `useMemo` in `useRowSelect` plugin

See original GitHub issue

I decided to pull this out of #2120 to give it proper focus, and also because if 2120 gets resolved in another way, I believe it is still important to see this fixed.

Describe the bug (required)

The useRowSelect plugins incurs side effects in a useMemo call.

This violates the useMemo pattern, and is the probable root cause for varied desynchronization and re-rendering rendering issues (eg #2159, #2120).

Provide an example via Codesandbox! (required)

See related bugs. Perhaps this is the simplest form, though its simplicity needs React.Strict to trigger a break.

In more complex code, it manifests itself as isSelected/selectedFlatRows desynchronization.

Steps To Reproduce

  • Go to useRowSelect.js:181.
  • Notice the lines that have side effects.
      row.isSelected = !!isSelected
      row.isSomeSelected = isSelected === null
    

Expected behavior

I see two possible approaches:

  • Better: properly derive isSelected from selectedRowIds (that is, make isSelected a useMemo with dependency on selectedRowIds)
  • Alternative: explore useLayoutEffect instead? Sounds kludgy.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

11reactions
tannerlinsleycommented, Aug 3, 2020

The amount of people running into this as of today are very few, and seeing how the issue will disappear in the next version, I don’t see a big pressing issue to fix this. That said, if the number of people experiencing this issue increases dramatically I will look into fixing it in v7. As always anyone coming across the this issue that wants to fix it is more than welcome to open a PR and I would be happy to guide them along the way.

8reactions
alverdalcommented, Jul 16, 2020

I ran into this issue today as well, was quite confused until I found this issue. perhaps it could be mentioned in documentation as a known issue until it’s fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Side effects in useMemo in useRowSelect plugin #2170
The useRowSelect plugins incurs side effects in a useMemo call. This violates the useMemo pattern, and is the probable root cause for varied ......
Read more >
React.useMemo and when you should use it - everyday.codes
The only difference is that useEffect is intended for side-effects (hence the name), while functions in useMemo are supposed to be pure and ......
Read more >
API Reference: Overview - React Table - TanStack
React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you...
Read more >
react-table - npm
React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you ......
Read more >
Changing column width in react-table - Stack Overflow
You need to use a layout hook (useBlockLayout, useAbsoluteLayout or useFlexLayout) so the specified width is applied.
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