Skip to content

fix: attachment upload broken after v2.0.0 upgrade (#1525)#1527

Merged
robinv8 merged 1 commit into
devfrom
fix/issue-1525-attachment-upload
May 19, 2026
Merged

fix: attachment upload broken after v2.0.0 upgrade (#1525)#1527
robinv8 merged 1 commit into
devfrom
fix/issue-1525-attachment-upload

Conversation

@robinv8
Copy link
Copy Markdown

@robinv8 robinv8 commented May 18, 2026

Problem

Fixes #1525. After upgrading to v2.0.0, file attachment uploads fail with:

RangeError: Invalid change range 0 to 33 (in doc of length 0)
    at replaceRange (base.ts:103)
    at onUpload (file.tsx:105)

Root Cause

file.tsx upload success handler called replaceRange('', startPos, endPos) to remove the loading placeholder, then replaceSelection(text) to insert the result. After replaceRange removes the text, the cursor position shifts, so replaceSelection inserts at the wrong location. More critically, replaceRange also requires the target range to exist in the document — if called with a stale endPos that's out of bounds, it throws a RangeError.

Fix

  • base.ts: Add missing replaceRange method to the CodeMirror adapter
  • file.tsx: Replace replaceRange('', ...) + replaceSelection(text) with a single replaceRange(text, startPos, endPos) call — atomically replaces the loading placeholder with the final link in one operation

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

- base.ts: add replaceRange method to CodeMirror adapter
- file.tsx: use replaceSelection to insert loading text (fixes RangeError)
- file.tsx: use useState/useEffect for stable editorState reference in async callbacks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@robinv8 robinv8 force-pushed the fix/issue-1525-attachment-upload branch from b99762e to 94c6c72 Compare May 18, 2026 15:01
@robinv8 robinv8 requested a review from Copilot May 18, 2026 15:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread ui/src/components/Editor/ToolBars/file.tsx
@robinv8 robinv8 merged commit 3164179 into dev May 19, 2026
4 checks passed
@robinv8 robinv8 deleted the fix/issue-1525-attachment-upload branch May 19, 2026 02:15
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.

2 participants