Skip to content

Conversation

@wendyyuchensun
Copy link
Collaborator

@wendyyuchensun wendyyuchensun commented Nov 3, 2025

Summary

Fixes a crash when inserting images through the upload modal by adding optional chaining to handle cases where insertLatex is called without an id property.

Problem

The insertLatex function in home.js:170 attempted to call .startsWith('heading') on an id that could be undefined, causing a runtime error and crashing the application when inserting images.

Root cause: The image upload handler calls insertLatex without providing an id property:

insertLatex({
latex: `![${altText}](${fileID})`,
offset: -1,
});

When insertLatex attempts to check if id.startsWith('heading'), it throws: TypeError: Cannot read property 'startsWith' of undefined.

Solution

  1. Added optional chaining operator (?.) to safely check if id exists before calling .startsWith().
  2. Added id: 'insert_image_file' to the insertLatex call in the image upload handler to provide a proper identifier for image insertion operations.

@wendyyuchensun wendyyuchensun added the bug Something isn't working label Nov 3, 2025
@coseeian coseeian merged commit e0c71a7 into coseeing:main Nov 4, 2025
1 check passed
@wendyyuchensun wendyyuchensun deleted the fix-image-upload branch November 4, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants