Prerequisites
Current Behavior
Right now, there are two issues when adding notes to assets:
- If you try to add a note to a new file that hasn't been scanned or indexed into
project.assets yet (or if project.assets is null/empty), the app immediately crashes with TypeError: assetsCopy.push is not a function.
- When you add or edit a note on an external resource (URL, external file, or folder), the note saves to disk, but the right-hand details pane abruptly closes because the resource gets deselected. You have to click it again in the tree to see your saved note.
Expected Behavior
- Adding a note to any asset—whether it's already indexed or brand-new—should save cleanly without crashing.
- Saving a note on an external resource should keep the item selected and leave the details pane open.
Possible Solution
I dug into the code and traced the root causes:
- In
Project.js, assetsCopy is a tree node object containing a children array, not an array itself. Calling .push() on it directly throws a type error. Pushing into assetsCopy.children and delegating to upsertNoteHandler should prevent the crash and ensure the note gets full metadata (UUID, author, timestamps).
- In
app/services/project.js, loadAndMergeProjectUpdates doesn't handle unregistered asset nodes when NOTE_ADDED fires, and _updateNote/_deleteNote lack null guards for missing entities. We can dynamically create the node with the right type (file, folder, URL) and attach it to the parent directory or root.
- In
Assets.js, the useEffect hook syncing the selected asset only searches project.assets. Because external resources live in project.externalAssets, the lookup returns null and resets the selection. Using AssetUtil.isExternalAsset() to check project.externalAssets should keep the item selected after saving.
I think this would be a clean way to address both issues so that local files and external resources handle note creation, editing, and deletion smoothly.
I'd love your thoughts:
- Does this sound like a solid fix to you?
- If so, I'd be happy to open a PR and get this resolved!
Your Environment
- Version used: 0.0.21 (Development branch)
- Environment: macOS / Node.js
Prerequisites
Current Behavior
Right now, there are two issues when adding notes to assets:
project.assetsyet (or ifproject.assetsis null/empty), the app immediately crashes withTypeError: assetsCopy.push is not a function.Expected Behavior
Possible Solution
I dug into the code and traced the root causes:
Project.js,assetsCopyis a tree node object containing achildrenarray, not an array itself. Calling.push()on it directly throws a type error. Pushing intoassetsCopy.childrenand delegating toupsertNoteHandlershould prevent the crash and ensure the note gets full metadata (UUID, author, timestamps).app/services/project.js,loadAndMergeProjectUpdatesdoesn't handle unregistered asset nodes whenNOTE_ADDEDfires, and_updateNote/_deleteNotelack null guards for missing entities. We can dynamically create the node with the right type (file, folder, URL) and attach it to the parent directory or root.Assets.js, theuseEffecthook syncing the selected asset only searchesproject.assets. Because external resources live inproject.externalAssets, the lookup returnsnulland resets the selection. UsingAssetUtil.isExternalAsset()to checkproject.externalAssetsshould keep the item selected after saving.I think this would be a clean way to address both issues so that local files and external resources handle note creation, editing, and deletion smoothly.
I'd love your thoughts:
Your Environment