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

Re-rendering a cell (by edit) renders the whole table #2824

Closed
danvln opened this issue Oct 31, 2020 · 29 comments
Closed

Re-rendering a cell (by edit) renders the whole table #2824

danvln opened this issue Oct 31, 2020 · 29 comments
Labels

Comments

@danvln
Copy link

danvln commented Oct 31, 2020

I am using the latest version 7.6.1, and I am hitting the issue that after I edit a single cell, I see the entire table being re-render.

This is similar with the issue called out here: #754 as far as I am reading.

Has been made any progress on the rendering performance for this table? I am planning to use it in a production system and this is a big blocker to move forward with it.

Thanks for any info.

@danvln
Copy link
Author

danvln commented Oct 31, 2020

I will update details. I am still investigating.

@bsubba
Copy link

bsubba commented Nov 4, 2020

I am also having the issue of re-rendering whole table. Did you find any solution for this?
#2836 (comment)

@stvhanna
Copy link

@danvln @bsubba I'm having the same issue. Any way to re-render just the impacted cell instead of the whole table?

@bsubba
Copy link

bsubba commented Jan 15, 2021

@stvhanna didn't autoResetPage: false help?

@stvhanna
Copy link

@bsubba Unfortunately it did not help. The delay on re-rendering ~2500 cells (100 rows x 25 columns) is substantial at 10s for each re-render.

@bsubba
Copy link

bsubba commented Jan 15, 2021

Is it possible to elaborate on what is it that you are trying to do and what is the problem?

@mugheerasadiq
Copy link

@danvln did you find any solution to stop the rendering of whole table ? I am facing the same issue but did not find any solution, Help needed

@codebex
Copy link

codebex commented Feb 5, 2021

I am also still looking for a good way to handle these re-renders. The alternative so far has been using a virtualization library (react-virtuoso) so the number of rows is small and the re-render does not take so much time. Also, I am trying memoization of "Cell" components, but I am not sure yet if it helps.

@mugheerasadiq
Copy link

@alaindm how did you memoize the cell components ? can you please give me an idea.

@einarq
Copy link

einarq commented Feb 23, 2021

The official stance on this library seems to be that re-rendering in react is fast, don't worry about it:
#1496 (comment)

This is a bit of a concern for us tbh. We are quite invested in this component by using it as the foundation for building a Table component for our design system, which is obviously used extensively across many of our applications.
I understand the sentiment that you should often start looking elsewhere to find performance bottlenecks, but in the end you might end up having to memoize components, and react-table makes that a bit difficult. Specifically memoizing the Row or Cell for instance doesn't work since the corresponding "row" and "cell" objects are seemingly always recreated whenever the table re-renders.
Adding more rows to the end, for instance, should not require re-rendering all existing rows as well. In addition to editing a single cell as described here.

A table with many rows and cells has always been a useful case for pure components, and I wish react-table made it possible in the future as well.
Even Dan mentions memo as a potential perf optimization in his latest blog post (albeit not the first), so it's still not completely out of fashion to prevent a few renders in React. It's an escape hatch which should still be supported imo.
https://overreacted.io/before-you-memo/

Hopefully this doesn't come across too much as a nagging complaint, I realize the author is in no way obligated to give us this component for free. Certainly appreciate the time spent on building this terrific library for us to enjoy.
Just wish it was possible to optimize it a bit more... :)

The article linked here, which is one of the top results when searching for how to optimize the table, gets around the issue by wrapping Row in React.memo. This would be my expected workaround as well, except it doesn't work when the Row needs to accept the "row" object.
#1496 (comment)

@tannerlinsley
Copy link
Collaborator

You're right that that some if not most of the methods/functions attached to rows and cells are being created on every render. I truly wish it was possible to alleviate this with the v7 architecture and this makes it almost impossible to memoize the component itself like you said without also calling all of the functions first, then memoizing on their results. This even plagues my own code in a few places :(

But there is good news! I'm currently working on v8 (a semi-private experimental stage repo on TanStack) which will not have this issue. It's taken a lot of internal refactoring and only a few breaking changes, but Row, cell and column models along with all of their methods and properties will all be stable by default. This will allow you to safely memo, useMemo and useCallback any of their properties. As of today, the rerendering story in v8 still uses a top-level rerender that propagates down the entire table tree and will, like you wish you could do today, incentivize memoization of components and computation where necessary to improve performance. It's possible that I explore more granular means of render signaling like subscription callbacks or even atom-based state like jotai, but that would significantly hinder the table's external controllability and complicate the innards quite a bit.

With the stability changes I've already made though, both the library's ability and your ability to memoize and optimize when needed is at least there now. Already in v8, I've been able to convert most of the up-front repeated instantiation of the row/cell API to be lazily-invoked memoized getters, which should drastically improve performance.

Either way, it should be really good. I hear you. Stay tuned :)

If you would like to preview the new version, give feedback, etc, it's currently open to my sponsorship tiers from Bronze up.

@einarq
Copy link

einarq commented Feb 23, 2021

Wow, that sounds terrific! Thanks for the honest and detailed response, this certainly alleviates my concerns quite a bit when it comes to being heavily invested in this component for the foreseeable future.

I'll see if anything can be done re sponsorship, not up to me unfortunately :)

@cargilltay
Copy link

@tannerlinsley Does react-table have a roadmap or planned release date for v8 and this improvement?

@tannerlinsley
Copy link
Collaborator

My hope is to have v8 out by the 3rd quarter of 2021

@danvln
Copy link
Author

danvln commented May 5, 2021

On my side I used virtualization but honestly that's a lot of pain but it works well with 10k+ elements. But now this leads to another problem that I described here: #2798 because it makes the table customizations quite impossible (or at least not possible with my knowledge on react-table in a feasible way, without creating N number of react-tables...). If you have any advise please let me know and I'll be glad to join the discussion.
On another thought @tannerlinsley would you be able to share the v8 code, and if is not possible I am willing to start helping in this effort on private repo. For transparency, I am a coder looking to contribute and no other interest as already have a good job in tech, I don't need credits for anything.
Please let me know, and also maybe other folks might be interested in helping.

@mspalma
Copy link

mspalma commented Aug 13, 2021

Hi. Having the same problem here. Is there a release date for v8? You mentioned 3rd quarter of 2021, any specific date?
Thank you

@danv-msft
Copy link

danv-msft commented Jan 24, 2022

@tannerlinsley - would you please let us know if there is any release date for v8 or a branch that's publicly available?

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Jan 25, 2022 via email

@danv-msft
Copy link

Thanks for your quick reply, @tannerlinsley . Do you plan to make it available soon and will it be still under MIT? I'm looking to make a decision regarding a grid I'm using with my team and wanted to double check on this option as well.

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Jan 25, 2022 via email

@luthv
Copy link

luthv commented Apr 1, 2022

I've been fiddling with the new v8 alpha release, and it seems that the problem is still persists in v8 as well. I didn't do any virtualization or anything, just basic custom cell component.
Is there anything else we should do in v8 to optimize cell rendering?

@tannerlinsley
Copy link
Collaborator

tannerlinsley commented Apr 1, 2022 via email

@luthv
Copy link

luthv commented Apr 1, 2022

Thanks, I was able to prevent re-render using React.memo in my Row component, here is what I ended up with
https://codesandbox.io/s/react-table-v8-xqs8d9?file=/src/Row.js

Previously when you click on a cell, all the rows will re-render because of the change in activeRow state in the App component.

Is this the correct way to optimize react table in this particular case?
Now the problem is that the column no longer supports resizing because of the memoized row component

@tannerlinsley
Copy link
Collaborator

As of today, v8 is as optimized as possible (correct keys, internal memoization/stable-api, etc) without getting into user code land. The official solution moving forward:

  • React.memo your rows/cells (and accept all of the tradeoffs with that approach)
  • Render/work less. Pagination, virtualize or simplify your cell components.

@loganvolkers
Copy link

Working on a jotai integration to help with the granular subscription to changes. Should be very doable as a layer on top of table-core, similar to the jotai integrations for redux, zustand, xstate, valtio and other bespoke state stores.

@thomasmarr
Copy link

@loganvolkers did you make much progress with that?

@loganvolkers
Copy link

@loganvolkers did you make much progress with that?

Not yet!

@thomasmarr
Copy link

Ok - I have an editable grid where the out-of-the-box behaviour was causing perf issues. I have implemented a workaround using react-query to subscribe to values in individual cells. It's effective, but it does add some complexity.

Inserting new columns and/or changing column visibility also requires the whole grid to re-render so I am still finding a need to React.memo the cells, with a custom callback.

Both of the above are things I prefer to avoid if possible, so am definitely interested in alternatives.

@jremen
Copy link

jremen commented Oct 19, 2023

@tannerlinsley
Well, we have 19. october 2023 and the issue with massive rerendering of table has still NOT BEEN RESOLVED.
Every select of the row will force all the cells in whole table to rerender. Every click on some input in cell will force all cells to rerender.
This is UNACCEPTABLE.

Heck, just try official examples on Code Sandbox, just put console.log to row selection example.
Everything we have done in our company is memoized. Still, no progress at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests