table icon indicating copy to clipboard operation
table copied to clipboard

Performance regression in 6.10.3

Open vsaarinen opened this issue 7 years ago • 7 comments

Using v6?

Yes

Describe the bug

Version 6.10.2 nicely fixed the constant re-mounting of cells that caused major performance issues. However, 6.10.3 is again very slow in my use. I believe the culprit is this commit: https://github.com/tannerlinsley/react-table/commit/9b2fc7680a365cd794cd3f1fe4f0a4943a53a42b

I don't know if this was intentional or not, but the logic in normalizeComponent changed: if typeof Comp !== 'function', the function used to always return fallback, but now it returns <Comp {...props} /> if isReactComponent(Comp) is true.

To Reproduce

In my case, the Cell properties of the objects in the columns array that I pass to <Table /> have a functional component, e.g.:

function Cell(props) {
  const data = React.useMemo(/* heavy computation */, [props.data]);
  ...
}

// inside the component rendering the table:
return <Table columns={[{..., Cell: cellInfo => <Cell data={cellInfo} />}]} ... />;

Expected behavior

The Cell component should stay mounted between rerenders, but appears to unmount and remount on each render. I noticed this because the Cell component makes a heavy computation on the initial render that is memoized using React.useMemo.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • Version 76

vsaarinen avatar Sep 16 '19 14:09 vsaarinen

Ooo. yeah. That's a case that wasn't taken into consideration. Could you make a PR to handle this case in the normalizeComponent function?

tannerlinsley avatar Sep 16 '19 15:09 tannerlinsley

I dug into this a bit. I'm still completely unfamiliar with react-table's code and how it should work, but here are the results for my case:

The regression doesn't seem to be caused by the change in the logic to normalizeComponent, but rather the change to this line: https://github.com/tannerlinsley/react-table/commit/9b2fc7680a365cd794cd3f1fe4f0a4943a53a42b#diff-2b4ca49d4bb0a774c4d4c1672d7aa781L228

The function that I give as the Cell property looks something like this when stringified:

      function Cell(cellInfo) {
        if (test(cellInfo)) {
          return null;
        }

        return react__WEBPACK_IMPORTED_MODULE_2___default.a.createElement(_Cell, {
          ...some_props,
        });
      }

In other words, the old version didn't detect this as a React function component while the new version does. I don't know which is correct, but the result is that the new version causes remounting of the component.

vsaarinen avatar Sep 17 '19 05:09 vsaarinen

I ran into an issue with a react-table 6.10.3 that I think may be related. In my case I have a table full of inputs which are rendered as functional components on the Cell prop of each column. On 6.10.3 each input would lose focus onChange (probably due to the cell un-mounting) which would only allow you to type one character and broke tabbing. Downgrading to 6.10.2 fixed this.

pixelwhip avatar Oct 14 '19 21:10 pixelwhip

@pixelwhip I'm also having this issue as well. However I only see the issue occurring when building for production.

henry-young avatar Oct 28 '19 22:10 henry-young

Have the same issue. Is it going to be fixed? I avoid the problem by using ver. 6.8.6 - it is the most stable version for 6.x branch at my opinion.

Kbdq avatar Nov 19 '19 10:11 Kbdq

Please use the newly created react-table-6 npm package and open any new issues with the [v6] tag. Remember, v6 is no longer being maintained with long-term support. I highly suggest migrating to v7.

tannerlinsley avatar Nov 20 '19 19:11 tannerlinsley

Still have the issue described by @pixelwhip even with version 6.11.5... @tannerlinsley Should I open a new issue for the problem?

Kbdq avatar Dec 12 '19 01:12 Kbdq