Replacing content of a notebook with json string programmatically in an extension

Hi
I’m working on a custom extension and I’m looking for a way to programmatically populate the notebook’s content with a JSON string.

I discovered this method: DocumentRegistry.IModel.fromString(value: string): void which does the job.

I have a notebook widget, so I simply call notebook.context.model.fromString(content), and it does indeed replaces the content of the notebook with my content JSON string.

However, I’m noticing this error in the console which is also triggered whenever I try to save anything to the notebook that has been populated with JSON string using fromString method:

The error mentions something about contentChanged. After looking through the docs of DocumentRegistry.IModel I discovered that it mentions the following in the description for fromString method: Should emit a [contentChanged] signal.

I’m wondering what it means and whether I’m missing something when I simply call the fromString method. Should there be something else I should be calling before/after fromString method in order to avoid the error? How exactly can I emit this signal?

Thanks in advance!

This was cross-posted at Replacing content of a notebook with json string in a custom extension · Discussion #862 · jupyterlite/jupyterlite · GitHub