fix(notes): rebase sidebar folder paths onto the configured notes root - #1225
Draft
h4yfans wants to merge 1 commit into
Draft
fix(notes): rebase sidebar folder paths onto the configured notes root#1225h4yfans wants to merge 1 commit into
h4yfans wants to merge 1 commit into
Conversation
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1204
What was wrong
Two producers feed the sidebar tree, and they used different bases:
notes:get-folders(notes-crud.tsgetFolders())<vault>/<defaultNoteFolder>)note.path(buildTreeFromNotes)'notes'literalEvery consumer is notes-root-relative —
folderExists, the folder view'sLIKEquery,.folder.mdconfig,
createNote({folder}),moveNote. So any node the renderer synthesised was in the wrongbase unless
defaultNoteFolderhappened to be exactly the stringnotes.With
defaultNoteFolder = "Notes", notes atNotes/x.mdproduced a phantomNotestree node whosepath resolved to
<vault>/Notes/Notes.folderExistsreturned false →folderNotFound→"Folder not found" on the grid button. Same literal appeared in the note breadcrumb, so crumbs opened
the same broken view.
The fix
Rebase note paths onto the configured notes root instead of a hardcoded literal, so the producer
and the consumer agree.
stripNotesRoot(notePath, notesRoot)innotes-tree-utils.tsx— tolerant, mirroringnoteFolderFromPathin@memry/app-coreextractFolderFromPathandbuildTreeFromNotestake the notes rootuseNotesRoot()inuse-vault.ts— a single string, refreshed on vault status change (changingdefaultNoteFoldertriggers a reindex, which emits one). Deliberately lighter thanuseVault()sothe tree does not re-render on index-progress ticks.
use-note-tree-data(tree build +computeTargetFolder, which feedscreateNote),use-note-tree-actions(move/drag targets), andnote-breadcrumbThe setting is not redefined —
defaultNoteFolderstays the notes root, which is what every mainprocess consumer already implements. No validation-on-write was added: with the producer fixed,
pointing the setting at an existing top-level folder is now a working configuration, so rejecting it
would be wrong.
Backward compatibility
Vault config shape, IPC contracts and on-disk layout are untouched; nothing is moved or migrated.
defaultNoteFolder = ''(today's default, no top-levelnotes/folder) — no behaviour change.defaultNoteFolder = 'notes'(legacy vaults, and the field's placeholder) — the old hardcoded stripand the new configured strip produce identical paths. No change.
defaultNoteFolder = ''and a real top-level folder namednotes/— behaviour changes, as afix: those notes used to be hoisted to the tree root while the
notesnode rendered empty. They nownest correctly, matching what
getFolders()already reported for that vault.Reverting the setting to empty still restores the previous view, as before.
Verification
pnpm exec vitest run --config config/vitest.config.ts --project rendererovernotes-tree-utils,use-note-tree-actions,note-sidebar-surfaces,notes-tree,virtualized-notes-tree,note,cold-zero-components,cold-major-components,app-sidebar→ 145 passed
pnpm lint→ 0 errors ·pnpm typecheck→ clean ·pnpm docs:build→ cleanpnpm docs:impact --base origin/main --strict→ docs changed on this branchRegression test —
notes-tree-utils.test.tsx, "does not emit a folder node for the notes rootitself":
defaultNoteFolder = 'Notes', notes atNotes/hello.mdandNotes/Work/alpha.md, foldersas
getFolders()reports them (['Work']). It asserts the tree's folder paths are exactly['Work']— no
Notesnode forfolderExiststo reject. Pre-fix, the tree also containedNotesandrootNoteswas empty, so the test fails onmain. Existing tests that encoded the hardcoded literalnow pass
'notes'explicitly, preserving their intent.Known gap (not fixed here)
Notes stored outside the notes root (e.g.
Archive/x.mdwhendefaultNoteFolder = 'Notes') arestill indexed and still shown, but their folder node cannot resolve under the notes root, so its grid
button reports "Folder not found". Handling those is a product call — hide them, hoist them to the
tree root, or widen the folder scope to the vault root — and is independent of this fix. Two more
copies of the same hardcoded
'notes'literal remain inlib/virtualized-tree-utils.ts(getParentFolderId, keyboard nav only) andpages/note.tsx(backlink folder label, display only); neither produces a folder-view scope.