Skip to content

Fix: fetchNote returns default empty entry instead of undefined#80

Merged
swuecho merged 1 commit intomasterfrom
fix/fetchnote-undefined-return
Feb 27, 2026
Merged

Fix: fetchNote returns default empty entry instead of undefined#80
swuecho merged 1 commit intomasterfrom
fix/fetchnote-undefined-return

Conversation

@swuecho
Copy link
Copy Markdown
Owner

@swuecho swuecho commented Feb 27, 2026

Summary

Fixed fetchNote in services/note.ts to always return a valid DiaryEntry instead of potentially returning undefined.

Problem

When a note didn't exist (new note or offline), fetchNote returned undefined, which could cause issues in consumers like DiaryEditor.vue.

Solution

  • Changed return type from Promise<DiaryEntry | undefined> to Promise<DiaryEntry>
  • Returns a default empty diary entry when note doesn't exist:
    {
      noteId,
      note: '',
      dirty: false,
    }

Benefits

  • Prevents undefined errors in consumers
  • Better UX for new notes - editor shows empty content instead of nothing
  • Type-safe: no need to handle undefined case

Testing

  • Create a new note (date that doesn't exist)
  • Verify editor shows empty content
  • Offline mode: verify new notes still work

- Changed return type from Promise<DiaryEntry | undefined> to Promise<DiaryEntry>
- Returns a default empty diary entry { noteId, note: '', dirty: false } when note doesn't exist
- Prevents undefined errors in consumers (DiaryEditor, etc.)
- Better UX for new notes - editor shows empty content instead of nothing
@swuecho swuecho merged commit 4c0385e into master Feb 27, 2026
2 checks passed
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.

1 participant