TriliumNext / Notes

Build your personal knowledge base with TriliumNext Notes
https://triliumnext.github.io/Docs/
GNU Affero General Public License v3.0
847 stars 46 forks source link

(Bug report) widget api.createNewNote Report an error #506

Open SiriusXT opened 3 days ago

SiriusXT commented 3 days ago

TriliumNext Version

0.90.8

What operating system are you using?

Windows

What is your setup?

Local + server sync

Operating System Version

Win11

Description

For this widget:

function creatHistory() {
    api.runOnBackend((noteId) => {
        const historyNote = api.createNewNote({
            parentNoteId: noteId,
            title: 'history',
            content: '{}',
            type: 'code',
            mime: 'application/json'
        });
    }, [api.startNote.noteId]);
}

creatHistory()

The test runs normally on 60.4, but an error is reported on 0.90.8: Error: Branch 'D6bymqShwce1_n3cbcZSSUwI2' has no child note 'n3cbcZSSUwI2'

Error logs

No response

eliandoran commented 20 hours ago

@SiriusXT , hmm... I've tried creating a new frontend code script and executing it with the "Run" button and it seems to run fine (creates a note called "History").

Can you give me the full widget and perhaps some instructions on how it is run? Could help me reproduce the issue.

SiriusXT commented 11 hours ago

The code above is the complete code I tested. I specifically created a new Trilium Next Desktop environment for testing, and I made some new discoveries:

  1. This bug occurs when the client restarts. If you directly click the execution button, the bug does not occur.
  2. The bug is not caused by an error in the code itself; the code consistently creates the history note successfully. The bug is caused by NoteTreeWidget.js: When generating the tree, it finds the branch related to the history but fails to find the history note (possibly due to a delay in the note's creation). This leads to an error being thrown in the prepareNode method of NoteTreeWidget.js.
  3. I can avoid this error by executing the widget after the tree is generated, for example, using setTimeout(() => {createHistory}, 1000);, and the error will no longer occur.

I will implement the widget through other means, so this bug is not urgent for me.