Skip to content

Dynamic item size uses estimateSize fallback when inside portal with dynamically created element #596

@HRworksVid

Description

@HRworksVid

Describe the bug

I don't know if this is a bug that can be fixed on your side but I experienced a strange behavior when rendering my virtualized list inside a portal. This occurs when I create an anchor for the portal inside useEffect and use the node created with document.createElement. If I use document.body or something reachable with document.getElementById instead, it works.

Context: I am using a ComboBox and render the list inside a dropdown or inside a modal on mobile devices. I did not notice it at first because in my development workflow the items usually get fetched after initially rendering the list. These items get cached based on the query so they don't have to fetched again. You can simulate this behavior by changing the default value in the example.

PS: Thanks for creating and maintaining this library!

Your minimal, reproducible example

https://codesandbox.io/p/sandbox/vigilant-kirch-v8q98r

Steps to reproduce

  1. Press "Open modal"
    => First items are squished
  2. Change createPortal container to document.body
  3. Reload and press "Open modal"
    => First items are not squished

Lazy: Change default state in the options from _options to null

  1. Press "Open modal"
    => First items are not squished

Expected behavior

Items are not squished

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

OS: Windows 11
Browser: Google Chrome 117.0.5938.132 64-Bit
React: 17.0.2 and 18.2.0

tanstack-virtual version

3.0.0-beta.61

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions