Fix preview mode stale content bug when switching notes (v0.1.1)
- Fixed race condition where image processing ran before localContent updated - Added synchronization guard to prevent processing stale content - Added comprehensive logging for debugging note switches - Bumped version to 0.1.1
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nextcloud-notes-tauri",
|
"name": "nextcloud-notes-tauri",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Nextcloud Notes",
|
"productName": "Nextcloud Notes",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"identifier": "com.davidrelich.nextcloud-notes",
|
"identifier": "com.davidrelich.nextcloud-notes",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "npm run dev",
|
"beforeDevCommand": "npm run dev",
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export class NextcloudAPI {
|
|||||||
webdavPath += `/${path}`;
|
webdavPath += `/${path}`;
|
||||||
|
|
||||||
const url = `${this.serverURL}${webdavPath}`;
|
const url = `${this.serverURL}${webdavPath}`;
|
||||||
console.log('Fetching attachment via WebDAV:', url);
|
console.log(`[Note ${_noteId}] Fetching attachment via WebDAV:`, url);
|
||||||
|
|
||||||
const response = await tauriFetch(url, {
|
const response = await tauriFetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -77,13 +77,23 @@ export function NoteEditor({ note, onUpdateNote, onUnsavedChanges, categories, i
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guard: Only process if localContent has been updated for the current note
|
||||||
|
// This prevents processing stale content from the previous note
|
||||||
|
if (previousNoteIdRef.current !== note.id) {
|
||||||
|
console.log(`[Note ${note.id}] Skipping image processing - waiting for content to sync (previousNoteIdRef: ${previousNoteIdRef.current})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const processImages = async () => {
|
const processImages = async () => {
|
||||||
|
console.log(`[Note ${note.id}] Processing images in preview mode. Content length: ${localContent.length}`);
|
||||||
setIsLoadingImages(true);
|
setIsLoadingImages(true);
|
||||||
|
setProcessedContent(''); // Clear old content immediately
|
||||||
|
|
||||||
// Find all image references in markdown: 
|
// Find all image references in markdown: 
|
||||||
const imageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g;
|
const imageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g;
|
||||||
let content = localContent;
|
let content = localContent;
|
||||||
const matches = [...localContent.matchAll(imageRegex)];
|
const matches = [...localContent.matchAll(imageRegex)];
|
||||||
|
console.log(`[Note ${note.id}] Found ${matches.length} images to process`);
|
||||||
|
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
const [fullMatch, alt, imagePath] = match;
|
const [fullMatch, alt, imagePath] = match;
|
||||||
@@ -121,11 +131,13 @@ export function NoteEditor({ note, onUpdateNote, onUnsavedChanges, categories, i
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadNewNote = () => {
|
const loadNewNote = () => {
|
||||||
if (note) {
|
if (note) {
|
||||||
|
console.log(`[Note ${note.id}] Loading note. Title: "${note.title}", Content length: ${note.content.length}`);
|
||||||
setLocalTitle(note.title);
|
setLocalTitle(note.title);
|
||||||
setLocalContent(note.content);
|
setLocalContent(note.content);
|
||||||
setLocalCategory(note.category || '');
|
setLocalCategory(note.category || '');
|
||||||
setLocalFavorite(note.favorite);
|
setLocalFavorite(note.favorite);
|
||||||
setHasUnsavedChanges(false);
|
setHasUnsavedChanges(false);
|
||||||
|
setProcessedContent(''); // Clear preview content immediately
|
||||||
|
|
||||||
const firstLine = note.content.split('\n')[0].replace(/^#+\s*/, '').trim();
|
const firstLine = note.content.split('\n')[0].replace(/^#+\s*/, '').trim();
|
||||||
const titleMatchesFirstLine = note.title === firstLine || note.title === firstLine.substring(0, 50);
|
const titleMatchesFirstLine = note.title === firstLine || note.title === firstLine.substring(0, 50);
|
||||||
@@ -136,10 +148,13 @@ export function NoteEditor({ note, onUpdateNote, onUnsavedChanges, categories, i
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (previousNoteIdRef.current !== null && previousNoteIdRef.current !== note?.id) {
|
if (previousNoteIdRef.current !== null && previousNoteIdRef.current !== note?.id) {
|
||||||
|
console.log(`Switching from note ${previousNoteIdRef.current} to note ${note?.id}`);
|
||||||
|
// Clear preview content immediately when switching notes
|
||||||
|
setProcessedContent('');
|
||||||
if (hasUnsavedChanges) {
|
if (hasUnsavedChanges) {
|
||||||
handleSave();
|
handleSave();
|
||||||
}
|
}
|
||||||
setTimeout(loadNewNote, 100);
|
loadNewNote();
|
||||||
} else {
|
} else {
|
||||||
loadNewNote();
|
loadNewNote();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user