Skip to content

Commit 514b62d

Browse files
authored
fix(virtual-core): update maybeNotify cache when deps change (#957)
1 parent f03d814 commit 514b62d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

.changeset/mean-lamps-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/virtual-core': patch
3+
---
4+
5+
fix(virtual-core): update maybeNotify cache when deps change

packages/virtual-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ export class Virtualizer<
734734
startIndex = range.startIndex
735735
endIndex = range.endIndex
736736
}
737+
this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex])
737738
return [
738739
this.options.rangeExtractor,
739740
this.options.overscan,

packages/virtual-core/src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function memo<TDeps extends ReadonlyArray<any>, TResult>(
1515
let deps = opts.initialDeps ?? []
1616
let result: TResult | undefined
1717

18-
return (): TResult => {
18+
function memoizedFunction(): TResult {
1919
let depTime: number
2020
if (opts.key && opts.debug?.()) depTime = Date.now()
2121

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

6767
return result
6868
}
69+
70+
// Attach updateDeps to the function itself
71+
memoizedFunction.updateDeps = (newDeps: [...TDeps]) => {
72+
deps = newDeps
73+
}
74+
75+
return memoizedFunction
6976
}
7077

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

0 commit comments

Comments
 (0)