Skip to content

fix(editor): initialize default page state for new blank notes - #7

Merged
Dronquavious merged 1 commit into
mathnotes-app:mainfrom
Dronquavious:fix/unresponsive-tools-new-note
Aug 15, 2026
Merged

fix(editor): initialize default page state for new blank notes#7
Dronquavious merged 1 commit into
mathnotes-app:mainfrom
Dronquavious:fix/unresponsive-tools-new-note

Conversation

@Dronquavious

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where non-drawing canvas tools (such as inserting images, creating text boxes, and selecting elements) are unresponsive when opening a new, blank note until an initial pen stroke is drawn.

Root Cause

When opening a new note, readNoteBody(id) returns null. NoteScreen previously left its enginePages state as an empty array ([]). Because InfiniteInkCanvas does not fire onPagesChange during initial mounting, enginePages.length remained 0.

This empty state caused:

  • Image insertion (applyInsertedImage) to calculate a target page index of -1 (Math.min(currentPageIndex, 0 - 1)), aborting image placement.
  • Text box creation (mutateOverlay) to look up enginePages[0], finding undefined and dropping overlay updates.
  • OverlayLayer screen-to-page coordinate mapping to fail.

Once any handwriting occurred, native drawing events triggered ensureSingleTrailingBlankPage(), which fired onPagesChange and synchronized enginePages, unblocking the remaining tools.

Proposed Changes

  • In app/note/[id].tsx, updated NoteScreen initialization so that when readNoteBody(id) returns null (for new notes), it falls back to a default 1-page SerializedNotebookData structure.
  • enginePages and overlayMap are now populated immediately upon note creation, and the initial page state is passed to canvasRef.current?.loadNotebookData().

Test Plan

  • Create a new blank note and immediately insert an image or text box without drawing first.
  • Verify existing notes with saved body data continue to load normally.
  • Ran npm run typecheck to confirm zero TypeScript errors.

@Dronquavious
Dronquavious merged commit 7745c68 into mathnotes-app:main Aug 15, 2026
1 check 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