outline / rich-markdown-editor

The open source React and Prosemirror based markdown editor that powers Outline. Want to try it out? Create an account:
https://www.getoutline.com
BSD 3-Clause "New" or "Revised" License
2.88k stars 590 forks source link

Editor crashes when feeding custom searchLinks #597

Closed SDAChess closed 2 years ago

SDAChess commented 2 years ago

When I create a custom search API with the onSearchLink prop, and click on the link to insert it, the following error is thrown :

Uncaught TypeError: href is undefined
    save LinkEditor.tsx:105
    handleSelectLink LinkEditor.tsx:262
    React 14
    unstable_runWithPriority scheduler.development.js:468
    React 17
    unstable_runWithPriority scheduler.development.js:468
    React 6
    dispatchTransaction index.tsx:569
    dispatch index.js:374
    readDOMChange domchange.js:84
    domObserver input.js:34
    flush domobserver.js:176
    onSelectionChange domobserver.js:122
    connectSelection domobserver.js:98
    selectionToDOM selection.js:71
    updateStateInner index.js:173
    updateState index.js:114
    dispatchTransaction index.tsx:551
    dispatch index.js:374
    readDOMChange domchange.js:244
    domObserver input.js:34
    flush domobserver.js:176
    observer domobserver.js:50
    DOMObserver domobserver.js:38
    initInput input.js:34
    EditorView index.js:66
    createView index.tsx:540
    init index.tsx:305
    componentDidMount index.tsx:221
    React 6
    unstable_runWithPriority scheduler.development.js:468
    React 9
    js index.js:7
    js main.chunk.js:1014
    Webpack 7
LinkEditor.tsx:105

Here is the snippet of my code (minimized) that still produces the error.

import Editor from "rich-markdown-editor";

import React from "react";

class Link {
    constructor(title, subtitle, link) {
        this.title = title;
        this.subtitle = subtitle;
        this.link = link;
    }

}

export default function MarkdownEditor(props) {
    return (
        <Editor
                onSearchLink={async searchTerm => {
                    return ["Test1", "Test2"].map(v => new Link(v, v, v))
                }}
        />
    );
}

I'm assuming this has to do with focus ?

Any ideas how to solve that one ?

Thank you very much.

SDA

SDAChess commented 2 years ago

I've also tried passing an anonymous object instead of a Link but had no luck doing so.

tommoor commented 2 years ago

The attribute on the results is url not link, as documented.