virtualizer.getVirtualItems() mismatches with number provided in count attribute during initialisation

Aberta
#666 0 comentários 3 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
react, typescript
Domínio
frontend

Direção de pesquisa

Comece pela configuração de useVirtualizer e rastreie como count, getVirtualItems() e getTotalSize() respondem quando as props mudam. É necessário um exemplo reproduzível antes de comparar a contagem de itens informada com o comportamento esperado da virtualização; considera-se concluído quando a discrepância é explicada ou corrigida e o resultado esperado é demonstrado.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Describe the bug

On Re-Render the number returned by virtualizer.getVirtualItems() is different than the number provided during initialisation of the virtualiser.

Initialising Virtualiser
const count = props.attributeGroups.length;
  const parentRef = React.useRef<HTMLDivElement>(null);
  const virtualizer = useVirtualizer({
    count,
    getScrollElement: () => parentRef.current,
    estimateSize: index => {
      const group = props.attributeGroups[index];
      let size = VIRTUALISED_ATTRIBUTE_GROUP_DEFAULT_SIZE;
      if (group) {
        size =
          group.attributes.length * VIRTUALISED_ATTRIBUTE_ELEMENT_DEFAULT_SIZE;
      }
      return size;
    },
    onChange: props.handleNavBarChangeOnScroll
  });

const items = virtualizer.getVirtualItems();
const totalSize = virtualizer.getTotalSize();



return (
    <div ref={parentRef}>
      <div id={`${props.currentMenu.name}-attributeGroupsContainer`} style={{ height: `${totalSize}px` }}>
        {items.map(virtualItem => (
          <div
            key={virtualItem.key}
            data-index={virtualItem.index}
            ref={virtualizer.measureElement}
            style={{
              position: "relative",
              width: "100%",
            }}
          >
            <GroupContainer
              {...props}
              key={props.attributeGroups[virtualItem.index].name}
              group={props.attributeGroups[virtualItem.index]}
            />
          </div>
        ))}
      </div>
    </div>
  );

Obeserved : In the above code with console.log(), items.length and count are different (items.length is 8 whereas count is 21) for some reason when props change but the totalSize however is computed for 21 components (more than required) due to which there is a empty section on the page.

Expected: Both items.length and count should be the same. (Please correct me if I am wrong in assuming this)

Regards,
Abhishek

Your minimal, reproducible example

NA

Steps to reproduce

NA

Expected behavior

Obeserved : In the above code with console.log(), items.length and count are different (items.length is 8 whereas count is 21) for some reason when props change but the totalSize however is computed for 21 components (more than required) due to which there is a empty section on the page.

Expected: Both items.length and count should be the same. (Please correct me if I am wrong in assuming this)

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

Chrome, Mozilla

tanstack-virtual version

3.0.0-beta.54

TypeScript version

4.9.5

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.
Linguagem predominante
TypeScript
Estrelas
7.2k
Forks
495
Merge médio
15h 11min
PRs com merge (30d)
17

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TanStack/virtual

Todas as issues de TanStack/virtual

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.