codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.7k stars 361 forks source link

Typing cursor out of sync on slow/proxied/domain environments #1421

Open josh-j opened 1 month ago

josh-j commented 1 month ago

Describe the issue

In the picture I typed 0123457890 and as I typed it, I see the cursor become more and more of sync. Additionally, when I type a letter I don't see it until maybe 100-200ms later (which is the case for every website with text input--so that's expected).

image

The problem becomes especially bad when I paste text.

Browser and platform

msedge/firefox/chrome - Windows 10

Reproduction link

No response

marijnh commented 1 month ago

I guess this is in the plain demo editor on codemirror.net? Is the issue that the cursor is in the wrong place, or that it updates slowly? I.e. in the screenshot, are there spaces after the number? The editor does nothing with the network, once it's loaded, so using a slow connection cannot really have any impact. Do you have any browser extensions enabled that may be interfering with the page?

josh-j commented 1 month ago

The screenshot is from codemirror.net. The issue is that the cursor is in the wrong place and stays in the wrong place until reload. There are no spaces after the number -- if I press backspace the last number is deleted even though the cursor suggests whitespace. This is done in a browser without any extensions installed -- just group policies applied and DLP (Trellix).

replit.com used to have the same issue for me (and it still sort of does, the cursor lags behind text but it eventually catches up and syncs).

Here you can see the more I type the worse it gets: image

josh-j commented 1 month ago

https://github.com/rstudio/rstudio/issues/2266

I can't create a gif/video of what I'm seeing at my workplace, but the gif in that issue is exactly what I'm experiencing.

marijnh commented 1 month ago

What may be happening is that the font file somehow loads after the editor script, causing the size of the code to change at a point where the editor has already initialized. I tried to reproduce this scenario with the devtools connection throttling, but didn't succeed—the code font loads much faster then the script. I guess there's something about the way your proxy behaves that produces this effect.

Are you able to test whether attached patch helps?