Repository navigation
Conversation
updateUriOfAllActiveFiles rebuilt each matching tab's URI as newUrl + basename, so a nested file such as src/components/Button.js became lib/Button.js after renaming src to lib. It also matched on a bare string prefix, so renaming or deleting src also rewrote or detached tabs under src-old/ or src2/. Match with Url.isSameOrDescendant and keep the file's path relative to the renamed folder. Renaming a single open file (openFolder.renameItem) now gives the new file URL instead of new.js/old.js.
Confidence Score: 4/5
[Medium impact] The change affects editor tabs during file and storage operations. The PR needs a SAF-only guard before merging so folder deletion cannot detach unrelated tabs. Findings
SummaryThe PR keeps nested tab paths intact after folder moves and renames.
The previous SAF storage-removal finding is fixed: matching documents now reach Reviews (2) · Last reviewed commit: "fix: detach tabs from a removed SAF stor..." · Reviewed by Greptile |
removeStorage passes a bare SAF tree URI, whose documents are <tree>::<docId>. Url.isSameOrDescendant only accepts a "/" boundary, so those tabs were no longer detached. Treat "<tree>::" as inside the removed root when detaching.
| // A SAF storage root is a bare tree URI; its documents are `<tree>::<docId>`. | ||
| if ( | ||
| Url.isSameOrDescendant(fileUrl, base) || | ||
| fileUrl.startsWith(`${base}::`) |
There was a problem hiding this comment.
Unrelated tabs lose their location
The new :: match applies to ordinary folders, not just SAF tree roots. Deleting sftp://profile/project/src also detaches a tab at sftp://profile/project/src::backup/index.js, even though that separate folder still exists. SFTP listings preserve these valid server filenames. The tab becomes marked deleted and loses its save location.
Limit this extra match to bare SAF tree URIs, and add a test that leaves a non-SAF sibling containing :: attached.
Bug
When a folder is renamed, moved (cut/paste) or deleted,
helpers.updateUriOfAllActiveFiles(src/utils/helpers.js) updates the open editor tabs that live under it. It has two defects:Url.join(newUrl, file.filename), i.e. new folder + basename. After renamingsrctolib, a tab forsrc/components/Button.jspoints atlib/Button.js.new RegExp("^" + escapeStringRegexp(url))with no/boundary, so renaming or deletingsrcalso rewrites or detaches tabs undersrc-old/…andsrc2/…. Renaming a single open file viaopenFolder.renameItem(old.js, new.js)givesnew.js/old.js, and also hitsold.json.Impact. The tab now points at a path that doesn't exist, so the file is reported as deleted and Save fails. If a same-named file exists at the flattened location (
src/components/index.js→lib/index.js), Save reads that other file, shows the "file has changed, overwrite?" prompt and, if confirmed, overwrites it with this tab's content.Callers:
openFolder.js(rename folder, delete folder, cut/paste folder,openFolder.renameItem) andfileBrowser.js.Fix
Match with the existing
Url.isSameOrDescendant(boundary-aware) and keep the file's path relative to the renamed folder:When detaching (
newUrlis null), a file is also treated as inside the root if its URI starts with<root>::.removeStoragepasses a bare SAF tree URI (…/tree/primary%3AX), and its documents are…/tree/primary%3AX::primary:X/….isSameOrDescendantalone would miss them.escapeStringRegexpis no longer used inhelpers.js, so its import is removed. Other files still use it.Tests
New
tests/unit/updateUriOfAllActiveFiles.test.js(5 cases) runs the realhelpers.js. All 5 fail onmain. The fifth case removes a SAF storage: it detaches that storage's tabs and leaves a…Testhtml2tree alone.With the fix all 5 pass. I also compared old and new behaviour over file, SAF (
content://…::primary:…), SFTP, FTP-with-query, root-folder, delete and unrelated-path cases. Only the buggy cases changed. Direct children, SAF/SFTP/FTP direct children, deletes of files inside the folder and unrelated paths produce the same URI as before.Local gate (macOS, Node 24):
npx vitest run1210 passed / 1 skipped (1205 + 5 new onmain),npm run typecheckclean,biome ci .clean,typosclean on the changed files. Not tested on a device.🤖 Generated with Claude Code