vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Can't click on links in streaming chat response

Open connor4312 opened this issue 2 years ago • 19 comments

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.

connor4312 avatar May 16 '24 01:05 connor4312

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

mjbvz avatar May 20 '24 18:05 mjbvz

Here's a quick print out of progressive rendering timing:

Image

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

mjbvz avatar May 21 '24 18:05 mjbvz

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?

roblourens avatar May 22 '24 02:05 roblourens

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.

roblourens avatar May 22 '24 02:05 roblourens

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

mjbvz avatar May 23 '24 00:05 mjbvz

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.

roblourens avatar May 23 '24 02:05 roblourens

Yeah that line you point out is suspicious and I suspect it should just be deleted.

roblourens avatar May 23 '24 02:05 roblourens

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!

roblourens avatar Jun 17 '24 01:06 roblourens

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

connor4312 avatar Jun 25 '24 17:06 connor4312

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

roblourens avatar Jun 26 '24 20:06 roblourens

  • Listen directly to mousedown/mouseup events an 'fake' a click if both of them happened on the equivalent element in the response.

connor4312 avatar Jun 26 '24 21:06 connor4312

Won't the same thing happen when those events land on a deleted element?

roblourens avatar Jun 26 '24 21:06 roblourens

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.

connor4312 avatar Jun 26 '24 21:06 connor4312

I see, you're right: https://codepen.io/roblourens/pen/ExzJKdo

roblourens avatar Jun 26 '24 21:06 roblourens

My first solution has some other benefits too and sounds fun at least, I might experiment with it. import 'react'

roblourens avatar Jun 26 '24 21:06 roblourens

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 :)

connor4312 avatar Jun 26 '24 21:06 connor4312

Whoa!

Also not losing focus

roblourens avatar Jun 26 '24 21:06 roblourens

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.

bpasero avatar Apr 30 '25 07:04 bpasero

Still an issue. Please fix this — I'm losing sleep over it 😭

hazicy avatar Nov 05 '26 12:11 hazicy