Can't click on links in streaming chat response
I wanted to go and see the file that copilot was talking about before its response finished. It seems like links to files and methods are detected in realtime, as they appear in blue in chat, but clicking on them does nothing until the response is finished.
This seems to be because the rendered markdown result is disposed of during progressive rendering, which disposes of the link handler
Been debugging but not sure why this happens while the markdown is still visible
Here's a quick print out of progressive rendering timing:
Notice how the current rendered text gets disposed of more than 50ms before the next text is rendered
We likely want to render the new text and then call dispose instead
Probably same as https://github.com/microsoft/vscode/issues/195949
I haven't looked into it in awhile but always suspected it's what you say- somehow related to the gap between disposing and rendering again. But, what should happen is everything gets disposed here
https://github.com/microsoft/vscode/blob/3d556065b0a9b2d856c8ab1352d5e37d419e5594/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts#L676
then immediately rerendered. Where are those logs from?
Just doing the render shouldn't take that long, but we could create a new DisposableStore each time, and wait to dispose the previous one until after the render.
Spent way too long trying to debug this. I believe what is happening is that partial rendering clears disposables here even if partsToRender doesn't re-render the markdown (the dom node is not cleared when this happened)
Still trying to figure out the best fix as some simple ones didn't work
I can investigate some more, I know this part of the code has gotten a little hairy. Would like to rework it at some point so adding new content types is easier.
Yeah that line you point out is suspicious and I suspect it should just be deleted.
I have an item on the iteration plan to do more changes to rendering which will fix this properly. For now, getting rid of this line is the best thing to do. Notes in https://github.com/microsoft/vscode/pull/215907. Thanks @mjbvz for the investigation earlier!
Testing https://github.com/microsoft/vscode/issues/217639, this is back. A little hard to see but notice my focus doesn't move into the editor the first time I click the link while the response is still streaming (or maybe it does but is captured back into chat?) After it finishes, it does.
https://memes.peet.io/img/24-06-6caa5a1b-2a81-4ee1-802d-86482c12608b.mp4
I guess I can repro this pretty easily in the right conditions, it just depends on how fast markdown is currently being rendered. This isn't related to disposables or the order that we set up new listeners and dispose the previous ones, it's just about clicking on an element at the same moment the element is removed from the DOM. It doesn't matter whether the listener is on the container or the actual element that gets removed, if you click on an element and remove that target before the click handler is run, then the event is totally lost.
Some solutions
- Try to stream markdown without constantly rerendering the whole thing- eg render the new bit, diff with the old, do a minimal update to the DOM. I'd like to try this but I think codeblocks make it a little harder
- We could detect when we're rendering a codeblock that's definitely already rendered the same amount, and put in a placeholder element instead of a real editor. Then an actually new codeblock gets a new editor.
- Initially set the element to display: none instead of removing it from the DOM
- Listen directly to mousedown/mouseup events an 'fake' a click if both of them happened on the equivalent element in the response.
Won't the same thing happen when those events land on a deleted element?
I'm thinking the "click" isn't working because the click event is sent after a mousedown+mouseup on the same element, and if the element is replaced between them it doesn't fire. So maybe manually handling those two events would fix the issue.
I see, you're right: https://codepen.io/roblourens/pen/ExzJKdo
My first solution has some other benefits too and sounds fun at least, I might experiment with it. import 'react'
That would also let us have some nicer animation as the response is streamed, I always felt like some kind of "fade in" on text as it's coming it would make it feel smoother and more polished :)
Whoa!
Also not losing focus
I also notice the progress spinner when edits are applied to stop whenever output is rendered, likely because everything gets rendered again and the animation restarts.
Still an issue. Please fix this — I'm losing sleep over it 😭