Step with document attribute causing focus out

Hello all,

I am trying to create unique id for a document on doc change, I used to store the Id in document attribute, I created a plugin and in appendTransaction() wrote my stuff, it works as expected but after executing the step the focus is missing from the document, what is wrong here?How can i retain the focus?

The problem only happens with document attribute change step… other step like AddMarkStep doesn’t have issues.

Here is my code snippet

export default class IdPlugin extends Plugin {

    	constructor() {

    			key: new PluginKey('IdPlugin'),
    			state: {
    				init(config, state) {},
    				apply(tr, set) {}
    			props: {
    				handleDOMEvents: {
    					keydown(view, event) {
    						const charCode = event.key;
    			appendTransaction: (transactions, prevState, nextState) => {
    				let tr = null;
    				tr = createId(prevState, nextState);
    				return tr;

    function createId(prevState, nextState, tr) {
    		tr =;
    		if( not exist){
    		tr = tr.step(new SetDocAttrStep('Id', uuid()));
    		return tr;

I can’t reproduce this—assuming a typical implementation of SetDocAttrStep, I don’t see the editor losing focus when changing document attributes.