Closed bcolloran closed 6 years ago
@bcolloran The notebook does save the render state of the MD cell, but the creation of the canvas
element happens in javascript in another cell. What gets saved in the value
field of the MD cell upon render doesn't capture any subsequent DOM manipulation. So when the cells get redrawn, we lose the appending of the canvas
element. This is actually a very interesting issue.
There are two solutions to this, not mutually exclusive.
DOMCell
type will be a good practice going forward for many of the reasons I've stated vocally. It creates enough separation between the textual presentation of a MarkdownCell
and the "data presentation" that a canvas
rendering won't get destroyed upon reload.MarkdownCell
to watch the inner HTML for changes, and save any changes to that in the value
field of the cell. This will maintain any subsequent DOM manipulations. There is a drawback that we are introducing new complexity to the MD rendering that might be hard to debug for the user.For the time being, I have a fix for this so we don't have to do any additional UI treatment while we implement the above. Essentially if in history view we'll still render the other cells, but will hide the container entirely so that the canvas elements don't get clobbered.
The workaround alluded to in the first comment is in c9ed5b483f6113fdfbfdf3117fca8dc0ba85f592.
Another reason why 1 above is my preferred solution is this: if I add a canvas
element to a Markdown cell via a javascript cell, and then I edit the content of the markdown cell, the canvas
element will be destroyed.
And of course if you add the canvas
element IN the MD cell, everything works as expected.
Should this be the expected behavior?
i'm actually happy with the behavior now that
I think we should close this, but i'll leave it to you since you broadened the scope (i'm happy to keep the scope narrow until needed, but if you want to keep this discussion open that's fine)
Yes, I think especially your 2nd point means we can close this.
accessing history undoes render state of MD cells-- in the e.g. THREE example, going to look at history somehow removes the reference to
targetDiv
and the cell defining it has to be run again.maybe history can be presented in a little window of some sort rather than paving over the whole window?