fix: stop triggerRefresh() after note creation to prevent stale cache overwrite in production
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 44s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 44s
In production (Docker/Next.js standalone), getAllNotes() can return cached results when called immediately after createNote(skipRevalidation:true). This caused newly created notes to disappear after the cache reload overwrote the optimistic local state. Fix: remove triggerRefresh() from both handleCreateNote (NotesTabsView) and handleNoteCreated (HomeClient). The note is already added optimistically to local state and does not need a server round-trip.
This commit is contained in:
@@ -123,7 +123,9 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
triggerRefresh()
|
// NOTE: No triggerRefresh() — note is added optimistically above.
|
||||||
|
// triggerRefresh() → getAllNotes() can return stale Next.js cache (note
|
||||||
|
// created with skipRevalidation:true) and overwrite the freshly-added note.
|
||||||
|
|
||||||
if (!note.notebookId) {
|
if (!note.notebookId) {
|
||||||
const wordCount = (note.content || '').trim().split(/\s+/).filter(w => w.length > 0).length
|
const wordCount = (note.content || '').trim().split(/\s+/).filter(w => w.length > 0).length
|
||||||
@@ -131,7 +133,7 @@ export function HomeClient({ initialNotes, initialSettings }: HomeClientProps) {
|
|||||||
setNotebookSuggestion({ noteId: note.id, content: note.content || '' })
|
setNotebookSuggestion({ noteId: note.id, content: note.content || '' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [searchParams, labels, router, triggerRefresh])
|
}, [searchParams, labels, router])
|
||||||
|
|
||||||
const handleOpenNote = (noteId: string) => {
|
const handleOpenNote = (noteId: string) => {
|
||||||
const note = notes.find(n => n.id === noteId)
|
const note = notes.find(n => n.id === noteId)
|
||||||
|
|||||||
@@ -760,7 +760,7 @@ export function NotesTabsView({
|
|||||||
startCreating(async () => {
|
startCreating(async () => {
|
||||||
try {
|
try {
|
||||||
const newNote = await createNote({
|
const newNote = await createNote({
|
||||||
content: noteType === 'checklist' ? '' : '',
|
content: '',
|
||||||
type: noteType,
|
type: noteType,
|
||||||
checkItems: noteType === 'checklist' ? [{ id: Date.now().toString(), text: '', checked: false }] : undefined,
|
checkItems: noteType === 'checklist' ? [{ id: Date.now().toString(), text: '', checked: false }] : undefined,
|
||||||
title: undefined,
|
title: undefined,
|
||||||
@@ -775,7 +775,9 @@ export function NotesTabsView({
|
|||||||
})
|
})
|
||||||
setSelectedId(newNote.id)
|
setSelectedId(newNote.id)
|
||||||
onNoteCreated?.(newNote)
|
onNoteCreated?.(newNote)
|
||||||
triggerRefresh()
|
// NOTE: No triggerRefresh() here — the note is already added to items above.
|
||||||
|
// triggerRefresh() would call getAllNotes() which may return stale cache
|
||||||
|
// in production (skipRevalidation:true skips cache invalidation).
|
||||||
} catch {
|
} catch {
|
||||||
toast.error(t('notes.createFailed') || 'Impossible de créer la note')
|
toast.error(t('notes.createFailed') || 'Impossible de créer la note')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user