Issue using update function to create bold element on fly from markdown (like in Typora)

I override update to convert all sequences like sometext to just bold text without asteriskes (like in Typora or HyperMD). The conversion is done, but when I enter any symbol right after convertion appeared, the source sequence returns. On a short videocast I show that (also with DOM model changes in chrome dev tools: . The source code from update provided below:

view.state.doc.descendants((node, pos) => {
                      if ( === 'text') {
                        nodeWithPos = findParentNodeOfType(mySchema.nodes.boldContainer)(TextSelection.create(view.state.doc, pos, pos))

                        if (!nodeWithPos) {
                          let matches = node.textContent.matchAll(/(\*\*)(.+)(\*\*)/gi)
                          matches = Array.from(matches)
                          matches.forEach(element => {
                            const newNode = mySchema.node('boldContainer', {}, [
                              mySchema.node('hidden', {}, mySchema.text('**')),
                              mySchema.node('boldText', { text: element[2] }, mySchema.text(element[2])),
                              mySchema.node('hidden', {}, mySchema.text('**'))
                            tr.replaceWith(pos + element.index, pos + element.index + element[0].length, newNode)

${selection.anchor} (size before resolving: ${tr.doc.content.size})`)

                    return false;

I appreciate any ideas!

This might be something in your custom nodes’ toDOM and parseDOM rules not matching up, causing the view to be unable to reparse such nodes.