Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

bug(web): Intermediate directory nodes in buildFileTree receive child leaf paths instead of directory paths

Aberta Para iniciantes
#1,707 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@riteshvish02 já está trabalhando nisso.

Desde 3/10/2026.

  • #1708 de @riteshvish02 — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
88/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
typescript
Domínio
api, frontend

Direção de pesquisa

Comece em packages/web/src/features/git/utils.ts, em buildFileTree, depois inspecione packages/web/src/app/(app)/browse/components/fileTreePanel.tsx e o endpoint getTree. Reproduza o exemplo de caminho aninhado e verifique se os nós de diretório intermediários expõem seus próprios caminhos de diretório, incluindo a expansão correta das pastas e a saída da API.

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

Descrição

Describe the Bug

In packages/web/src/features/git/utils.ts, buildFileTree constructs a nested FileTreeNode hierarchy from a flat list of { type, path } objects.

When creating intermediate directory nodes (lines 68-74), the new node's path property is assigned item.path (the full path of the current leaf file being processed), instead of the path of that directory:

// packages/web/src/features/git/utils.ts:67-75
if (!next) {
    next = {
        name: part,
        path: item.path, // <--- Bug: assigns leaf file's path to intermediate directory node
        type: nodeType,
        children: [],
    };
    current.children.push(next);
}
Impact
  1. Broken Folder State & Expansion in UI: In packages/web/src/app/(app)/browse/components/fileTreePanel.tsx, folder expand/collapse state is tracked via openPaths.has(node.path) and route sync via pathParts.slice(0, i + 1).join('/'). Because directory nodes receive the child file's path instead of their own directory path, clicking folders or deep-linking to nested paths causes folder state tracking and auto-expansion to fail.
  2. Public API Corruption: The getTree endpoint (/api/git/tree) returns FileTreeNode with corrupted directory paths to API consumers.
Reproduction
const flatList = [
    { type: 'blob', path: 'src/components/buttons/PrimaryButton.tsx' }
];

const tree = buildFileTree(flatList);
const srcDir = tree.children[0];
console.log(srcDir.name); // "src"
console.log(srcDir.path); // Expected "src", but Got "src/components/buttons/PrimaryButton.tsx"
Proposed Fix

Reconstruct the directory node's path using parts.slice(0, i + 1).join('/'):

if (!next) {
    next = {
        name: part,
        path: parts.slice(0, i + 1).join('/'),
        type: nodeType,
        children: [],
    };
    current.children.push(next);
}

For intermediate directory levels (i < parts.length - 1), this evaluates to the proper directory path (e.g. "src", "src/components"), and for leaf files (i === parts.length - 1), it matches item.path.

Linguagem predominante
TypeScript
Estrelas
3.9k
Forks
374
Merge médio
17h 15min
PRs com merge (30d)
38

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 sourcebot-dev/sourcebot

Todas as issues de sourcebot-dev/sourcebot

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.