Skip to content

fix: switching between notes may override note#336

Open
redeck1 wants to merge 2 commits intomainfrom
fix/note-content-override-when-switching-between-notes
Open

fix: switching between notes may override note#336
redeck1 wants to merge 2 commits intomainfrom
fix/note-content-override-when-switching-between-notes

Conversation

@redeck1
Copy link

@redeck1 redeck1 commented Jan 12, 2026

Fixed autosave and quick tab switching. The note id might not match the id in the url

@vercel
Copy link

vercel bot commented Jan 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
codex-ui Ready Ready Preview, Comment Jan 13, 2026 8:42pm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes race conditions that occur when users quickly switch between notes, which could result in data from one note being saved to or displayed for another note. The fix involves capturing note IDs before async operations and validating that the current note ID hasn't changed after async operations complete.

Changes:

  • Added race condition checks in the load() function to prevent setting note data if the current ID changed during the async fetch
  • Captured note ID before save operations to ensure content is saved to the correct note even if the user switches notes during the save
  • Updated the noteTitle watcher to use note ID instead of route path for better consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 409 to 420
watch(noteTitle, (currentNoteTitle) => {
if (route.name == 'note') {
patchOpenedPageByUrl(
route.path,
{
title: currentNoteTitle,
url: route.path,
});
if (route.name == 'note' && currentId.value !== null) {
/**
* URL may have changed, use note id
*/
const noteUrl = `/note/${currentId.value}`;

patchOpenedPageByUrl(noteUrl, {
title: currentNoteTitle,
url: noteUrl,
});
}
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The noteTitle watcher has a potential race condition. While currentId.value is checked, it's not captured at the time the watcher is triggered. If currentId changes between when noteTitle is recalculated and when this watcher callback runs, the title from one note could be used to update the opened page for a different note. Consider capturing currentId.value at the start of the watcher callback, similar to how savedNoteId is captured in the save function.

Copilot uses AI. Check for mistakes.
title: currentNoteTitle,
url: route.path,
});
if (route.name == 'note' && currentId.value !== null) {
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strict equality (===) instead of loose equality (==) for consistency with the rest of the codebase and to avoid potential type coercion issues.

Suggested change
if (route.name == 'note' && currentId.value !== null) {
if (route.name === 'note' && currentId.value !== null) {

Copilot uses AI. Check for mistakes.
@neSpecc
Copy link
Member

neSpecc commented Feb 7, 2026

Please explain the exact root cause of the problem in the PR description and how your fix resolves it.

const specifiedNoteTools = resolveToolsByContent(content);

/**
* Id may be changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSdoc is not clear for me, please explain the case.

const response = await noteService.getNoteById(id);

/**
* Id changed, loaded another note
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, explain the case more straightforward

Comment on lines +218 to +220
if (currentId.value !== id) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't understand why we need to check this condition one more time here (you've checked it right above, what is the difference here?)

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.

3 participants