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.

useScrollTop is very slow

See original GitHub issue

Hi, I’m testing @next and I noticed most of the time on scroll is spent on the useScrollTop hook, it leads to very long frames.

image

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
FezVrastacommented, Nov 25, 2020

This is the relevant code (I use react-table):

const footer = useCallback(() => {
  if (firstRow == null) {
    return null;
  }
  prepareRow(firstRow);

  return Array.from({
    length: Math.min(10, totalCount - rows.length),
  }).map((_, i) => <PlaceholderRow row={firstRow} key={i} />);
}, [prepareRow, rows.length, firstRow, totalCount]);

const components = useMemo(
  () => ({
    EmptyPlaceholder: loading ? null : EmptyComponent,
  }),
  [loading]
);

const itemContent = useCallback(
  (index) => {
    const row = rows[index];
    prepareRow(row);
    return (
      <Row
        row={row}
        onRowClick={onRowClick}
        onAddToQueue={onAddToQueue}
        onStartRead={onStartRead}
        onView={onView}
        onRemove={onRemove}
        onCompare={onCompare}
        tab={tab}
        isScrolling={isScrolling}
      />
    );
  },
  [
    isScrolling,
    onAddToQueue,
    onCompare,
    onRemove,
    onRowClick,
    onStartRead,
    onView,
    prepareRow,
    rows,
    tab,
  ]
);

<Virtuoso
  css={`
    flex: 1;
    overflow-x: hidden;
    ${style};
  `}
  totalCount={rows.length}
  endReached={onFetchMore}
  isScrolling={setIsScrolling}
  overscan={1000}
  footer={footer}
  components={components}
  defaultItemHeight={51}
  itemContent={itemContent}
/>
2reactions
FezVrastacommented, Nov 25, 2020

I’m quite convinced the issue resides in Virtuoso, I recently tried to swap it with react-window and the performances were way better, but of course I lost all the nice features that Virtuoso provides out of the box.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll to top in nested Drawer navigation - Stack Overflow
I have a nested Drawer navigation and want to scroll to top on every screen change, I am using UseScrollToTop hook as described...
Read more >
React Component to Smooth Scroll to the Top
Just import this component in your react file and stick it at the very end. And voila, it should work! Here is a...
Read more >
React Native Flastlist onScroll slow : r/reactnative - Reddit
Hey guys, can someone please help me with getting a smooth animation ... toString(); const ref = useRef(null); useScrollToTop(ref); const ...
Read more >
useScrollToTop - React Navigation
useScrollToTop. The expected native behavior of scrollable components is to respond to events from navigation that will scroll to top when tapping on...
Read more >
5 Reasons Why Your React Native App is Slow - In Plain English
React Native application are really slow most of the times. Large sets of the list, images, assets, API responses and multiple rendering, ...
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