Skip to content

fix(open-folder): refresh renamed entries with URI-aware matching#2142

Merged
bajrangCoder merged 3 commits into
Acode-Foundation:mainfrom
bajrangCoder:fix/open-folder-rename-refresh
May 31, 2026
Merged

fix(open-folder): refresh renamed entries with URI-aware matching#2142
bajrangCoder merged 3 commits into
Acode-Foundation:mainfrom
bajrangCoder:fix/open-folder-rename-refresh

Conversation

@bajrangCoder
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 31, 2026

Greptile Summary

This PR replaces in-place DOM mutation (textContent, dataset, collapse/expand click simulation) for rename operations with a full parent-directory re-render approach, and introduces URI-aware URL comparison to handle content: SAF URIs and trailing-slash variants correctly.

  • FileTree.refreshFolder (new): recursively walks expanded childTrees until it finds the subtree whose currentUrl matches the target URL, then calls refresh() on that node only — fixing the root-level re-render regression described in the previous review thread.
  • URI normalization helpers (normalizeUrlPathKey, areSameOpenFolderUrl, isInsideOpenFolder): replace the fragile regex-based openFolder.find logic with deterministic comparison that strips trailing slashes and canonicalises content: document URIs via rootUri::docId.
  • migrateOpenFolderStateUrls: migrates saved expanded-folder keys in listState to their post-rename equivalents so the sidebar restores prior expand state after a rename.

Confidence Score: 4/5

Safe to merge for the primary rename flow; the only rough edge is SAF content: URI expanded-state migration, which silently drops sidebar expand state after a rename of nested directories on Android SAF — no data loss.

The new refreshFolder traversal and URI-normalization logic handle the common cases correctly. The one gap is in migrateOpenFolderStateUrls: for content: SAF URIs the suffix is computed from the normalized rootUri::docId form (where the docId uses real / separators) but appended to the original document URI (which encodes those separators as %2F). This means post-rename expanded-state keys in listState will be in the wrong format and the sidebar will not restore prior expand state for SAF nested directories.

src/lib/openFolder.js — specifically migrateOpenFolderStateUrls and the appendUrlPathSuffix call for content: URI entries.

Important Files Changed

Filename Overview
src/components/fileTree/index.js Adds refreshFolder(url, isSameUrl) — a clean recursive traversal over childTrees that refreshes only the matching subtree instead of always re-rendering the root.
src/lib/openFolder.js Refactors rename handling to use parent-directory re-render and adds URI normalization utilities; expanded-state migration for SAF content: URIs may produce incorrect keys due to a mismatch between normalized-key suffix and original URI encoding.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant EO as execOperation / renameItem
    participant RREOF as refreshRenamedEntryInOpenFolders
    participant MOFS as migrateOpenFolderStateUrls
    participant ROF as refreshOpenFolder
    participant OFind as openFolder.find
    participant FT as FileTree (root)
    participant CT as FileTree (child subtree)

    U->>EO: rename(url → newUrl)
    EO->>RREOF: (url, newUrl)
    RREOF->>MOFS: migrate listState keys
    MOFS-->>RREOF: listState updated
    RREOF->>ROF: refreshOpenFolder(oldParentUrl)
    ROF->>OFind: find(oldParentUrl)
    OFind-->>ROF: root Folder object
    ROF->>FT: refreshFolder(oldParentUrl, areSameOpenFolderUrl)
    FT->>FT: "currentUrl == oldParentUrl? NO"
    loop childTrees
        FT->>CT: refreshFolder(oldParentUrl, ...)
        CT->>CT: "currentUrl == oldParentUrl? YES"
        CT->>CT: refresh() → load(currentUrl)
        CT-->>FT: true
    end
    FT-->>ROF: true
    ROF-->>RREOF: done
    RREOF-->>EO: done
Loading

Reviews (3): Last reviewed commit: "fix the edge case" | Re-trigger Greptile

Comment thread src/lib/openFolder.js
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

@UnschooledGamer
Copy link
Copy Markdown
Member

We're back at our hacky URL transformations.

@bajrangCoder
Copy link
Copy Markdown
Member Author

We're back at our hacky URL transformations.

Yeah, we need it to handle different

@bajrangCoder bajrangCoder merged commit f9428af into Acode-Foundation:main May 31, 2026
7 checks passed
@bajrangCoder bajrangCoder deleted the fix/open-folder-rename-refresh branch May 31, 2026 07:22
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.

2 participants