setSelection Creates Duplicate Nodes

Hi, I am inserting a node into the doc and setting the selection to the node’s inner text section with a text Selection.

This is executed as a command using the Enter key

Fo some reason, it duplicates the vueComponent node. Here is my code :

import * as example from 'prosemirror-state'

export default function () {
  return ({ tr, schema, selection, doc }, dispatch, view) => {
    const { $anchor } = selection
    const node = $anchor.node(1)
    const isCard = node ? === 'vueComponent' : false

    if (isCard) {
      const pos = $anchor.after(1)
      const paragraph = schema.nodes.vueComponent

      if (dispatch) {
        tr.insert(pos, paragraph.createAndFill())

        // dispatch(tr)
        const selections = example.TextSelection.create(tr.doc, pos + 1)

        return true
    return false

Solution: the issue was that it was interacting with the default Enter functionality causing a strange duplicate bug.