-
-
Notifications
You must be signed in to change notification settings - Fork 442
feat(benchmarks): add React Aria Virtualizer to cross-library harness #1205
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
Open
Stanzilla
wants to merge
5
commits into
TanStack:main
Choose a base branch
from
Stanzilla:feat/benchmark-react-aria-virtualizer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+759
−18
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6623d66
feat(benchmarks): add React Aria Virtualizer to cross-library harness
Stanzilla 06353bd
fix(benchmarks): address PR review feedback for RAC harness
Stanzilla cac26b9
fix(benchmarks): address follow-up PR review on tanstack-rac
Stanzilla 5d90c61
docs(benchmarks): add RAC comparison results and exclusion typing
Stanzilla b513200
fix(benchmarks): type scenario exclusions with LibraryName keys
Stanzilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { Item } from './dataset' | ||
|
|
||
| export function ItemRow({ | ||
| item, | ||
| itemSize, | ||
| dynamic, | ||
| index, | ||
| }: { | ||
| item: Item | ||
| itemSize: number | ||
| dynamic: boolean | ||
| index: number | ||
| }) { | ||
| return ( | ||
| <div | ||
| data-index={index} | ||
| className={'item ' + (index % 2 === 0 ? 'even' : '')} | ||
| style={{ | ||
| minHeight: dynamic ? undefined : itemSize, | ||
| boxSizing: 'border-box', | ||
| }} | ||
| > | ||
| {item.text} | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import type { ListLayout } from 'react-aria-components' | ||
| import type { HarnessHandle } from './harness' | ||
| import type { ScenarioInput } from '../scenarios/types' | ||
| import type { Item } from './dataset' | ||
|
|
||
| export function findRacScrollContainer( | ||
| root: HTMLElement | null, | ||
| ): HTMLElement | null { | ||
| if (!root) return null | ||
| for (const node of root.querySelectorAll('div')) { | ||
| const el = node as HTMLElement | ||
| const oy = getComputedStyle(el).overflowY | ||
| if (oy === 'auto' || oy === 'scroll') return el | ||
| } | ||
| return root | ||
| } | ||
|
|
||
| export function scrollRacToIndex( | ||
| container: HTMLElement, | ||
| layout: ListLayout<unknown> | null, | ||
| items: Array<Item>, | ||
| index: number, | ||
| itemSize: number, | ||
| align: 'start' | 'end' = 'start', | ||
| ): void { | ||
| const key = items[index]?.id ?? index | ||
|
|
||
| for (let attempt = 0; attempt < 4; attempt++) { | ||
| let scrollTop = index * itemSize | ||
|
|
||
| if (layout?.virtualizer) { | ||
| layout.update({}) | ||
| layout.getLayoutInfo(key) | ||
| const layoutInfo = layout.getLayoutInfo(key) | ||
| if (layoutInfo) { | ||
| scrollTop = | ||
| align === 'end' | ||
| ? layoutInfo.rect.y + layoutInfo.rect.height - container.clientHeight | ||
| : layoutInfo.rect.y | ||
| } | ||
| } else if (align === 'end') { | ||
| scrollTop += itemSize - container.clientHeight | ||
| } | ||
|
|
||
| const maxScroll = Math.max( | ||
| 0, | ||
| container.scrollHeight - container.clientHeight, | ||
| ) | ||
| container.scrollTop = Math.max(0, Math.min(scrollTop, maxScroll)) | ||
| container.scrollTo({ top: container.scrollTop, behavior: 'instant' }) | ||
| container.dispatchEvent(new Event('scroll', { bubbles: true })) | ||
| } | ||
| } | ||
|
|
||
| export function createRacVirtualHarness({ | ||
| hostRef, | ||
| scrollerRef, | ||
| layoutRef, | ||
| items, | ||
| scenario, | ||
| }: { | ||
| hostRef: { current: HTMLDivElement | null } | ||
| scrollerRef: { current: HTMLElement | null } | ||
| layoutRef: { current: ListLayout<unknown> | null } | ||
| items: Array<Item> | ||
| scenario: ScenarioInput | ||
| }): Omit<HarnessHandle, 'getScrollContainer'> & { | ||
| getScrollContainer: () => HTMLElement | null | ||
| } { | ||
| return { | ||
| getScrollContainer: () => | ||
| scrollerRef.current ?? findRacScrollContainer(hostRef.current), | ||
| getSearchRoot: () => hostRef.current, | ||
| scrollToIndex: (index, opts) => { | ||
| const container = | ||
| scrollerRef.current ?? findRacScrollContainer(hostRef.current) | ||
| if (!container) return | ||
| scrollRacToIndex( | ||
| container, | ||
| layoutRef.current, | ||
| items, | ||
| index, | ||
| scenario.itemSize, | ||
| opts?.align ?? 'start', | ||
| ) | ||
| }, | ||
| getTotalSize: () => { | ||
| const container = | ||
| scrollerRef.current ?? findRacScrollContainer(hostRef.current) | ||
| if (!container) return 0 | ||
| const content = container.firstElementChild as HTMLElement | null | ||
| return content?.offsetHeight ?? container.scrollHeight | ||
| }, | ||
| isFullyMeasured: () => { | ||
| if (!scenario.dynamic) return true | ||
| const container = | ||
| scrollerRef.current ?? findRacScrollContainer(hostRef.current) | ||
| const total = container?.scrollHeight ?? 0 | ||
| const estimate = scenario.count * scenario.itemSize | ||
| return total > 0 && total !== estimate | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export function cacheRacScroller( | ||
| host: HTMLDivElement | null, | ||
| scrollerRef: { current: HTMLElement | null }, | ||
| ): void { | ||
| const scroller = findRacScrollContainer(host) | ||
| if (scroller) { | ||
| scrollerRef.current = scroller | ||
| scroller.dataset.benchRacScroller = 'true' | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.