Medium.js icon indicating copy to clipboard operation
Medium.js copied to clipboard

Uncaught IndexSizeError: Failed to execute 'setStart' on 'Range':

Open matheusbras opened this issue 10 years ago • 15 comments

I'm getting this error after typing a few letters. Any ideia what could it be? I'm using Chrome 37.0.2062.94. Thanks!

Uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 2.

matheusbras avatar Sep 06 '14 02:09 matheusbras

Can you tell me which options, mode, and behavior you are using? On Sep 5, 2014 10:26 PM, "Matheus Bras Quaresma" [email protected] wrote:

I'm getting this error after typing a few letters. Any ideia what could it be? I'm using Chrome 37.0.2062.94. Thanks!

Uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 2.

— Reply to this email directly or view it on GitHub https://github.com/jakiestfu/Medium.js/issues/82.

robertleeplummerjr avatar Sep 06 '14 16:09 robertleeplummerjr

@robertleeplummerjr I'm using with the default options, just passing the element.

matheusbras avatar Sep 19 '14 23:09 matheusbras

So then you are using the demo's? If so, which example?

On Fri, Sep 19, 2014 at 7:48 PM, Matheus Bras Quaresma < [email protected]> wrote:

@robertleeplummerjr https://github.com/robertleeplummerjr I'm using with the default options, just passing the element.

— Reply to this email directly or view it on GitHub https://github.com/jakiestfu/Medium.js/issues/82#issuecomment-56249394.

Robert Plummer

robertleeplummerjr avatar Sep 20 '14 00:09 robertleeplummerjr

I'm having the same problem.

Building inside a React component and enabling in either componentDidMount or componentDidUpdate.

The options I'm using are:

new Medium({
        element: this.getDOMNode().querySelector('.preview-content'),
        mode: Medium.richMode,
        autoHR: false,
        cssClasses: {
          editor: 'edit-mode',
        }
      })

All works fine until you delete the node's innerText and start typing again, at which point the caret jumps around and ends up at the start of the node.

Uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': 
There is no child at offset 2.medium.js:1404 Medium.Cursor.setmedium.js:1305 
Medium.Utilities.setupContentsmedium.js:1601 
Medium.HtmlAssistant.placeholdersmedium.js:240 intercept.up

Currently on Chrome:39

tomatau avatar Jan 21 '15 15:01 tomatau

Same error in partialMode.. inlineMode works fine.. the bug only happens after typing a few characters fairly quickly

edit: no it happens when creating slowly.. seems that when the first

is added the range gets messed up.

Bug also happens in Rich mode demo.

tomatau avatar Jan 21 '15 15:01 tomatau

This makes it work

tags: {
  paragraph: null
}

but now inserting unnecessary <div> tags where a <br> would be more suitable for the text content. Also seems hacky, if more complex behaviour would be introduced for e.g. highlighting the first word.

tomatau avatar Jan 21 '15 15:01 tomatau

What are the exact steps to reproduce?

robertleeplummerjr avatar Jan 24 '15 12:01 robertleeplummerjr

Click on the editor for the rich editor in your demo, press delete twice (you'll see the caret position change slightly despite their being no text), then type three characters very quickly.

From then on - the error happens seemingly randomly in your demo but more consistently in other implementations. The first page load can produce the error consistently.

tomatau avatar Jan 24 '15 18:01 tomatau

Try latest from master.

On Sat, Jan 24, 2015 at 1:43 PM, Thomas [email protected] wrote:

Click on the editor for the rich editor in your demo, press delete twice (you'll see the caret position change slightly despite their being no text), then type three characters very quickly.

From then on - the error happens seemingly randomly in your demo but more consistently in other implementations. The first page load can produce the error consistently.

— Reply to this email directly or view it on GitHub https://github.com/jakiestfu/Medium.js/issues/82#issuecomment-71331560.

Robert Plummer

robertleeplummerjr avatar Jan 24 '15 21:01 robertleeplummerjr

Mmm did you bump the version at all after making this change? I'm noticing no difference for my implementation.

edit: your demo page still performs exactly the same too

tomatau avatar Feb 02 '15 11:02 tomatau

Here's a video demonstrating the behaviour - you can see the code used to implement and the current version tracked by npm.

MediumJSErrorDemo.sm.mov | uploaded via ZenHub

tomatau avatar Feb 04 '15 10:02 tomatau

Any fixes on that? Having the same issue here..

vkovalskiy avatar May 31 '15 21:05 vkovalskiy

Same for me, I get this when trying to set a value or typing in anything but inlineMode.

janwirth avatar May 04 '16 00:05 janwirth

I was encountering this issue when trying to wrap it in a medium directive and using any mode other than inline.

@vkovalskiy @levity I found a different, probably more hacky workaround: https://github.com/FranzSkuffka/innovant/blob/firebase-wip/assets/libs/medium.js#L1404

just wrap the call in a try / catch construct and things will work as expected.

janwirth avatar May 23 '16 21:05 janwirth

For what it's worth, I also just ran into a very similar issue (mine was an Uncaught DOMexception Failed to execute 'setEnd' on 'Range': The offset 1 is larger than or equal to the node's length (0)).

The problem for me was caused by a Chrome extensions that was going in and modifying the DOM elements on the page under codemirror's nose (in my case it was this text url to clickable url extension - which would break codemirror if I had a URL in the editor contents).

Disabling that extension resolved the issue for me.

ivanov avatar Dec 08 '16 00:12 ivanov