the block widget disappeared after add or remove a new line

We have a block widget like this.

let widget = Decoration.widget({
      widget: new GroupWidget(lines[ln].groupID),
      side: -1,
      block: true,
});
widgets.push(widget.range(line.from));

It works fine in CM5 but in CM6, whenever I add or remove a line, the block widget will disappear. It only shows up again when I type in some text in the lines. Do you know what happened?

Can you show a full code example on codemirror.net/try?

It seems like the problem is that every time user makes a change to the CM, the widget will be rendered before the CM’s onChange function is called. In our logic, the widget rendering logic depends on the output of the onChange and because of that the widget is rendered wrongly.
Also, I noticed the widget is also recomputed several times after CM’s onChange but the widget outlook didn’t change at all.

I tried to simulate the onchange event here but don’t know how to do it properly Try CodeMirror. I am using a react version of CM (React CodeMirror - CodeMirror component for React.).

Also, I wonder how widget calculation got triggered and how I force that to be recalculated after on change. I have tried view.update([]) but it did not work.

If by onChange you mean updateListener, that’s expected. If you need to track state for changes, and use that for rendering, you’re probably going to have a better time keeping it in a state field.