Skip to content

fix(file-browser): sync open folder tree after delete#2031

Merged
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/custom-fs-issue-in-sidebar
Apr 14, 2026
Merged

fix(file-browser): sync open folder tree after delete#2031
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/custom-fs-issue-in-sidebar

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

Fixes: #2028

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR fixes a stale-state bug where deleting a file or folder removed the DOM element directly without calling FileTree.removeEntry, leaving the component's this.entries array out of sync (which would cause deleted items to reappear on tree refresh). The fix extracts a shared removeEntryFromOpenFolder helper that routes through ownerTree.removeEntry when an element belongs to a FileTree instance, and also unifies the same logic in openFolder.removeItem — picking up CSS.escape protection as a side effect.

Confidence Score: 5/5

  • Safe to merge — the fix correctly addresses both the stale-entries bug and the previously noted CSS.escape gap, with a sound fallback path for non-FileTree elements.
  • No P0 or P1 issues found. The _fileTree lookup at two DOM levels (parent / grandparent) correctly maps to both file tiles and folder title elements in the current structure, matching the existing pattern in getLoadedFileTree. VirtualList is effectively disabled (threshold = Infinity) so the fragment-mode path covers all real cases today.
  • No files require special attention.

Important Files Changed

Filename Overview
src/lib/openFolder.js Introduces removeEntryFromOpenFolder to delegate deletion to FileTree.removeEntry, keeping the component's this.entries array in sync; also reuses this helper in openFolder.removeItem (which previously lacked CSS.escape). One concern: the _fileTree lookup depth is hard-coded to two levels and may silently miss elements if the DOM nesting ever changes (e.g. when VirtualList is re-enabled).

Sequence Diagram

sequenceDiagram
    participant User
    participant execOperation
    participant removeEntryFromOpenFolder
    participant sidebarApps
    participant FileTree

    User->>execOperation: right-click → Delete
    execOperation->>execOperation: fsOperation(url).delete()
    execOperation->>removeEntryFromOpenFolder: removeEntryFromOpenFolder(url)
    removeEntryFromOpenFolder->>sidebarApps: "getAll([data-url="CSS.escape(url)"])"
    sidebarApps-->>removeEntryFromOpenFolder: $els[]
    loop for each $el
        removeEntryFromOpenFolder->>removeEntryFromOpenFolder: resolve ownerTree via _fileTree
        alt ownerTree found
            removeEntryFromOpenFolder->>FileTree: ownerTree.removeEntry(url)
            FileTree->>FileTree: splice entries[]
            FileTree->>FileTree: remove DOM element
        else no ownerTree
            removeEntryFromOpenFolder->>removeEntryFromOpenFolder: direct DOM remove
        end
    end
    execOperation->>execOperation: editorManager.onupdate / emit
Loading

Reviews (2): Last reviewed commit: "fix" | Re-trigger Greptile

@bajrangCoder

This comment was marked as outdated.

@bajrangCoder bajrangCoder merged commit 2fbf95d into Acode-Foundation:main Apr 14, 2026
7 checks passed
@bajrangCoder bajrangCoder deleted the fix/custom-fs-issue-in-sidebar branch April 14, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom FS UI shows deleted file after create (lsDir not called after delete)

1 participant