Skip to content

Instantly share code, notes, and snippets.

@bvaughn
Created September 5, 2019 18:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvaughn/ee224481282c7bc1b278aa31c6a517e0 to your computer and use it in GitHub Desktop.
Save bvaughn/ee224481282c7bc1b278aa31c6a517e0 to your computer and use it in GitHub Desktop.
Pre-rendering virtual rows

Pre-rendering virtual rows

Example list with ten total rows and a viewport large enough to display two rows.

Legend

█ - Visible row ▓ - Hidden/display-locked row ░ - Empty space (nothing rendered here)

Initial case

Sync priority commit renders enough rows to fill the viewport. Below them is empty space.

0 ███ ┑
1 ███ ┙
2 ░░░
3 ░░░
4 ░░░
5 ░░░
6 ░░░
7 ░░░
8 ░░░
9 ░░░

Idle priority update pre-renders another chunk of rows below the viewport. These rows are hidden and display-locked so that both React and the browser knows they're lower priority. Above and below these new rows is empty space.

0 ███ ┑
1 ███ ┙
2 ▓▓▓
3 ▓▓▓
4 ░░░
5 ░░░
6 ░░░
7 ░░░
8 ░░░
9 ░░░

Ideal update

User scrolls, causing the viewport to move within the range of pre-rendered rows. Sync priority commit updates all rendered rows. One previously visible/unlocked row is updated to be hidden/locked. One previously hidden/locked row is updated ot be visible/unlocked.

0 ▓▓▓
1 ███ ┑
2 ███ ┙
3 ▓▓▓
4 ░░░
5 ░░░
6 ░░░
7 ░░░
8 ░░░
9 ░░░

Idle priority update adusts the pre-rendered rows to center around the new viewport.

0 ▓▓▓
1 ███ ┑
2 ███ ┙
3 ▓▓▓
4 ▓▓▓
5 ░░░
6 ░░░
7 ░░░
8 ░░░
9 ░░░

Non-ideal update

User scrolls quickly, causing the viewport to move beyond the range of pre-rendered rows. Sync priority commit renders enough rows to fill the viewport.

0 ░░░
1 ░░░
2 ░░░
3 ░░░
4 ███ ┑
5 ███ ┙
6 ░░░
7 ░░░
8 ░░░
9 ░░░

Idle priority update adusts the pre-rendered rows to center around the new viewport.

0 ░░░
1 ░░░
2 ▓▓▓
3 ▓▓▓
4 ███ ┑
5 ███ ┙
6 ▓▓▓
7 ▓▓▓
8 ░░░
9 ░░░
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment