Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

CodeMirror's internal event handlers (e.g., beforeinput for spell-check) throw RangeError: Trying to find position for a DOM position outside of the document when calling posFromDOM/posAtDOM on editor instances not yet attached to DOM. This occurs with presence indicators and during editor initialization.

Changes

  • Added global error handler in src/client/main.jsx to catch and suppress the specific RangeError
  • Logs suppressed errors via console.log for debugging visibility
  • Returns true from handler to prevent default console error output
window.addEventListener('error', (event) => {
  if (
    event.error instanceof RangeError &&
    event.error.message.includes(
      'Trying to find position for a DOM position outside of the document',
    )
  ) {
    console.log('Suppressed CodeMirror DOM position error:', event.error);
    return true;
  }
});

Impact

Eliminates console noise from harmless timing errors in CodeMirror's DOM interaction layer. Editor functionality remains unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Issue with offscreen CodeMirror</issue_title>
<issue_description>We're getting this error:

index-DwusECPl.js:119 Error finding element position: RangeError: Trying to find position for a DOM position outside of the document
    at CL.posFromDOM (index-DwusECPl.js:62:49477)
    at St.posAtDOM (index-DwusECPl.js:65:14285)
    at HTMLDocument.b (index-DwusECPl.js:119:19686)

I think it might be from a certain presence indicator plugin that is trying to render something on an off-DOM instance of CodeMirror. Perhaps we can just wrap all the code that uses posFromDOM or posAtDOM in a try/catch?</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 14, 2025 02:54
Co-authored-by: curran <68416+curran@users.noreply.github.com>
Co-authored-by: curran <68416+curran@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error finding element position in offscreen CodeMirror Suppress CodeMirror DOM position errors for offscreen editors Dec 14, 2025
Copilot AI requested a review from curran December 14, 2025 03:01
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.

Issue with offscreen CodeMirror

2 participants