wavetermdev / waveterm

An open-source, cross-platform terminal for seamless workflows
https://www.waveterm.dev
Apache License 2.0
4.16k stars 105 forks source link

Markdown render() method called repeatedly on block focus #725

Open mattmutt opened 2 months ago

mattmutt commented 2 months ago

Describe the bug When having a few markdown documents rendered in WaveTerm, merely clicking on the cells to change focus will invoke render() from the Markdown class each time.

Since merely clicking or focusing on a cell is not changing any of the public properties that it depends on - and it already executed and rendered, there should not be an additional call to re-render in React.

We nested React components inside the Markdown, and therefore they are impacted by the Markdown class having to re-render. Is there a way to stop the propagation of the render whenever focusing or clicking on past cells in the WaveTerm view?

To Reproduce Steps to reproduce the behavior:

Open two markdown documents in WaveTerm:

mdview example1.md

and then in next cell

mdview example2.md

Add a simple console.debug in the render() method for the Markdown class.

Then to verify, restart WaveTerm and click between the two cells.

Expected behavior

Markdown once rendered, does not undergo any more visual re-rendering as it is disruptive to others in that take advantage of building new markdownComponents

Screenshots

Every click will emit a console debug message similar to mine in the right hand side Chrome dev tools.

markdown-render-calls

Desktop (please complete the following information):

Additional context

Goal is to be able to have more interactive content in the form of custom React widgets shown when the markdown renders. Because the user might click on a different block and then come back, we don't want our nested widgets to re-render, which makes it start from the start again.

I know markdown should be simple, but the point is that we can actually build some bit of interactivity. Calling another render() is too destructive.

mattmutt commented 1 month ago

@sawka just a small checkup to see if you could share your opinion. Can the re-rendering cycles be limited somehow? We might be able to get around it somehow, but fundamentally the re-rendering is causing some glitches when we have components that are not just simple text in the output area. Essentially they "lose" their state, flash a little and render to the starting state.