Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'replaceChild' of null #22

Open
rj-david opened this issue Jul 14, 2019 · 6 comments
Open

TypeError: Cannot read property 'replaceChild' of null #22

rj-david opened this issue Jul 14, 2019 · 6 comments

Comments

@rj-david
Copy link

Getting this error

/node_modules/prosemirror-menu/dist/index.js:542 Uncaught (in promise) TypeError: Cannot read property 'replaceChild' of null
    at new MenuBarView (/node_modules/prosemirror-menu/dist/index.js:542)
    at Object.view (/node_modules/prosemirror-menu/dist/index.js:527)
    at EditorView.updatePluginViews (/node_modules/prosemirror-view/dist/index.js:4481)
    at new EditorView (/node_modules/prosemirror-view/dist/index.js:4344)
@nowakkamil
Copy link

I'm not sure if what I'm about to suggest would resolve this issue, but let's give it a shot. Are you sure that there is a div with editor id in your DOM? By default, document.querySelector("#editor") is invoked while setting up EditorView.

@marijnh
Copy link
Member

marijnh commented May 21, 2021

By default, document.querySelector("#editor") is invoked while setting up EditorView.

No, that's not accurate—the library will append to the element is it given, and doesn't hard-code any specific ids.

Not sure why I missed this issue initially. @rj-david Did you solve this? If not, you're going to have to provide more details.

@nowakkamil
Copy link

Yes, I missed one crucial piece of information, and as such, my previous comment is not accurate. I wanted to point out that the code resulting in the error might have originated from the basic example. If so, it seems that the div with editor id was not present in DOM. I used the code snippet from the URL above and had an error with the same title. After adding a div with editor id to DOM prior to the script execution, the issue was resolved for me.

@Rene-Montes
Copy link

Rene-Montes commented Jun 16, 2021

We are hitting this constantly in production (we are working on a different editor that doesn't use prosemirror-menu):

+-----------------------------------------------------------------------+-------------------------------------------------------------+------+--------+
| function                                                              | file                                                        | line | column |
+-----------------------------------------------------------------------+-------------------------------------------------------------+------+--------+
| editorView.dom.parentNode.replaceChild(this.wrapper, editorView.dom); | webpack:///./node_modules/prosemirror-menu/dist/index.es.js | 670  | 28     |
| return new MenuBarView(editorView, options);                          | webpack:///./node_modules/prosemirror-menu/dist/index.es.js | 653  | 13     |
| this.pluginViews.push(plugin.spec.view(this));                        | webpack:///./node_modules/prosemirror-view/dist/index.es.js | 6771 | 42     |
| this.updatePluginViews();                                             | webpack:///./node_modules/prosemirror-view/dist/index.es.js | 6584 | 7      |
| let view = new EditorView(editor, {                                   | webpack:///./app/javascript/etc/prosemirror.js              | 16   | 15     |
| document.querySelectorAll('.markdown-content').forEach(mdc => {       | webpack:///./app/javascript/etc/prosemirror.js              | 12   | 49     |
| }), (null != u ? u : document).dispatchEvent(i), i;                   | webpack:///./node_modules/turbolinks/dist/turbolinks.js     | 75   | 39     |
| return null == t && (t = {}), e.dispatch("turbolinks:load", {         | webpack:///./node_modules/turbolinks/dist/turbolinks.js     | 994  | 42     |
| return this.notifyApplicationAfterPageLoad(t.getTimingMetrics());     | webpack:///./node_modules/turbolinks/dist/turbolinks.js     | 1007 | 22     |
+-----------------------------------------------------------------------+-------------------------------------------------------------+------+--------+

@marijnh
Copy link
Member

marijnh commented Jun 17, 2021

That would happen when you create an editor that isn't in the DOM. We could add a condition to not call replaceChild in that situation, but that would mean you wouldn't see the menu bar, which is probably also not what you're looking for. So for now my advice would be to make sure you're not using the menu with 'detached' editors (that were created with null as first constructor argument)

@Rene-Montes
Copy link

Probably would have saved us time if it just said that I was missing an editorView element :) We were unintentionally initializing an editor without an element

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

No branches or pull requests

4 participants