Skip to content

Uncaught RangeError: Position -1 out of range when creating a new editor instance #1145

Closed
@Akshdhiwar

Description

@Akshdhiwar

Description:
I encountered an Uncaught RangeError: Position -1 out of range error while creating a new editor instance in my project. This happens when a new editor is initialized in "editing mode." Below is the stack trace:

chunk-LTEZDJSH.js?v=1bc2ccfc:7965 Uncaught RangeError: Position -1 out of range
    at _ResolvedPos.resolve (chunk-LTEZDJSH.js?v=1bc2ccfc:7965:13)
    at _ResolvedPos.resolveCached (chunk-LTEZDJSH.js?v=1bc2ccfc:7991:63)
    at _Node.resolve (chunk-LTEZDJSH.js?v=1bc2ccfc:8251:24)
    at new MouseDown (chunk-LTEZDJSH.js?v=1bc2ccfc:19892:33)
    at handlers.mousedown (chunk-LTEZDJSH.js?v=1bc2ccfc:19869:28)
    at view.dom.addEventListener.view.input.eventHandlers.<computed> (chunk-LTEZDJSH.js?v=1bc2ccfc:19660:9)

Steps to Reproduce:

Create a new editor instance using the following code:


// Editor instance
const editor = useMemo(() => {
    let editor: any
    if (isEditing) {
        const doc = new Y.Doc();
        const provider = new YPartyKitProvider(
            "blocknote-dev.yousefed.partykit.dev",
            project?.Id! + selectedFolder?.id,
            doc,
        );
        editor = BNE.create({
            collaboration: {
                provider,
                fragment: doc.getXmlFragment("document-store"),
                user: {
                    name: user?.GithubName!,
                    color: getRandomColor() // blue color
                }
            }
        });
    } else {
        editor = BNE.create({
            initialContent: pageContent
        });
    }

    return editor;
}, [selectedFolder, isEditing, pageContent]);

Expected Behavior:
The editor should initialize properly and allow user interaction without any errors.

Actual Behavior:
The error Position -1 out of range occurs when trying to resolve a position within the document, possibly related to mouse input handling.

It works normal after a re-render of component but on initialization it throws a error.
Please free to give your suggestion on this if I'm doing something wrong or so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions