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

Improve Solid adapter. #790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/solid-virtual/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@tanstack/virtual-core'

import {
createComputed,
createEffect,
createSignal,
mergeProps,
onCleanup,
Expand Down Expand Up @@ -55,22 +55,19 @@ function createVirtualizerBase<
}

const virtualizer = new Proxy(instance, handler)
virtualizer.setOptions(resolvedOptions)

onMount(() => {
const cleanup = virtualizer._didMount()
virtualizer._willUpdate()
onCleanup(cleanup)
})

createComputed(() => {
createEffect(() => {
virtualizer.setOptions(
mergeProps(resolvedOptions, options, {
onChange: (
instance: Virtualizer<TScrollElement, TItemElement>,
sync: boolean,
) => {
instance._willUpdate()
setVirtualItems(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should batch the set state calls together.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest here?

reconcile(instance.getVirtualItems(), {
key: 'index',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also make this 'key' rather than 'index' so that it uses any custom supplied key from getItemKey option for the diff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it should be key

Expand All @@ -81,6 +78,8 @@ function createVirtualizerBase<
},
}),
)
setVirtualItems([])
virtualizer._willUpdate()
virtualizer.measure()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw the measure here looks suspicious

})

Expand Down
Loading