Is view.requestMeasure required when a block widget changes height?

I have a block widget which renders its contents asynchronously. The documentation says that the widget should call view.requestMeasure if the height of the widget changes:

if you dynamically change their height, you should make sure to call requestMeasure, so that the editor can update its information about its vertical layout.

CodeMirror Reference Manual

However, it seems in my experience so far that the editor’s height map is correct even if the block widget doesn’t call view.requestMeasure.

Is it always a requirement to call view.requestMeasure() after updating the contents of a widget, if the height changes?

If so, would it be possible to add view as a second parameter to the updateDOM method of WidgetType, so that both toDOM and updateDOM can call view.requestMeasure()?

It is safest to do so, though as you found recent versions of @codemirror/view will also automatically remeasure themselves when the content height changes. It would be possible though, to still end up with incorrect height info if you change a bunch of widgets in such a way that their total height stays the same.

Yes, that seems like a good idea. Done in this patch.

1 Like