-
Notifications
You must be signed in to change notification settings - Fork 6
fix: switching between notes may override note #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: switching between notes may override note #336
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this 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.
| 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, | ||
| }); | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| title: currentNoteTitle, | ||
| url: route.path, | ||
| }); | ||
| if (route.name == 'note' && currentId.value !== null) { |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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.
| if (route.name == 'note' && currentId.value !== null) { | |
| if (route.name === 'note' && currentId.value !== null) { |
Fixed autosave and quick tab switching. The note id might not match the id in the url