Skip to content

Changing the gap option dynamically does not invalidate cached measurements #1222

Description

@2wheeh

Describe the bug

Changing gap after mount does not recompute item start or getTotalSize().

The list keeps the layout from the old gap.

The same value on a fresh mount lays out correctly, so only the dynamic update path is broken (remount is the only workaround).

Your minimal, reproducible example

https://stackblitz.com/~/github.com/2wheeh/virtual-gap-dynamic-repro

Steps to reproduce

  1. Click gap 40 (setState → re-render with the new gap).
  2. See the rendered gap is stale:
actual   starts [0, 50, 100, 150, 200]  total 250   // stale gap=0 layout
expected starts [0, 90, 180, 270, 360]  total 410
  1. Click Remount (workaround): the same gap: 40 lays out correctly.

Expected behavior

Updating gap should invalidate the measurements, keeping the layout reactive to option changes.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

not platform-specific

tanstack-virtual version

@tanstack/react-virtual 3.14.5 / @tanstack/virtual-core 3.17.3

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions