Slate: Inline IsVoid block throws "Unable to find DOM node" error when selection changes

Created on 30 Oct 2018  Â·  5Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Report a bug

What's the current behavior?

After inserting an inline block that has IsVoid in the schema, moving the selection on to the block throws an "unable to find DOM node" error. The inline component does have its incoming attributes prop spread and the schema also has IsVoid set to true. The problem does not reproduce if the button is changed to insertBlock instead of insertInline.

Image component

import React from "react";

export default class Image extends React.Component {
  render() {
    return (
      <img {...this.props.attributes} src={this.props.node.data.get("src")} />
    );
  }
}

Schema

{
  blocks: {
    image: {
      isVoid: true
    }
  }
}

Codesandbox example

Image of bug

What's the expected behavior?

The editor shouldn't crash and should allow selection.

bug ♥ help

Most helpful comment

@rfeltis you inserted the image using insertInlinebut your schema is basically setting image only as a blocks. if you change your schema to

{
  inlines: {
    image: {
      isVoid: true
    }
  }
}

or use insertBlock as your image then it should be good.

@ianstormtaylor not sure if we want to put this as a bug. It's more like the isVoid check through schema is not explained enough on the documentation. Same issue as https://github.com/ianstormtaylor/slate/issues/2219

All 5 comments

In my case I am inserting a @mention inline node like this.
`
change.insertInline({
type: 'Mention',
data: {
Name: selectedUser.Name,
Id: selectedUser._id,
Type: selectedUser.Kind
},
isVoid: true
}).moveToEndOfInline().focus().insertText(" ..... ")

`
the text .... is not inserted anymore.

@saravanan10393 I think the isVoid has to be defined in schema now

@rfeltis you inserted the image using insertInlinebut your schema is basically setting image only as a blocks. if you change your schema to

{
  inlines: {
    image: {
      isVoid: true
    }
  }
}

or use insertBlock as your image then it should be good.

@ianstormtaylor not sure if we want to put this as a bug. It's more like the isVoid check through schema is not explained enough on the documentation. Same issue as https://github.com/ianstormtaylor/slate/issues/2219

That fixed it! You are likely right that the docs could help point in the right direction. The schemas guide doesn't mention that there is an inlines section. The only time it comes up is at the top of the schemas reference guide. I honestly didn't even remember typing in blocks for the section. I thought it was nodes all this time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexeiAndreev picture AlexeiAndreev  Â·  3Comments

vdms picture vdms  Â·  3Comments

JSH3R0 picture JSH3R0  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments