Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/mean-lamps-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/virtual-core': patch
---

fix(virtual-core): update maybeNotify cache when deps change
1 change: 1 addition & 0 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ export class Virtualizer<
startIndex = range.startIndex
endIndex = range.endIndex
}
this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex])
return [
this.options.rangeExtractor,
this.options.overscan,
Expand Down
9 changes: 8 additions & 1 deletion packages/virtual-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function memo<TDeps extends ReadonlyArray<any>, TResult>(
let deps = opts.initialDeps ?? []
let result: TResult | undefined

return (): TResult => {
function memoizedFunction(): TResult {
let depTime: number
if (opts.key && opts.debug?.()) depTime = Date.now()

Expand Down Expand Up @@ -66,6 +66,13 @@ export function memo<TDeps extends ReadonlyArray<any>, TResult>(

return result
}

// Attach updateDeps to the function itself
memoizedFunction.updateDeps = (newDeps: [...TDeps]) => {
deps = newDeps
}

return memoizedFunction
}

export function notUndefined<T>(value: T | undefined, msg?: string): T {
Expand Down