-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The content is different under different operating systems (can be reproduce in the monaco demo) #6
Comments
Hi @chenyjade The problem is probably related to y-webrtc. There are know sync-issues between different browsers & platforms. yjs/y-webrtc#19 Another problem is that y-webrtc seems to drop some messages if they are deemed too large (or for some other unknown reasons that I haven't figured out yet). There is help (yjs/y-webrtc#20), but I need time to investigate this problem. You are welcome to research the problem yourself. I currently don't have enough free time to work on it myself. |
This problem seems to be related to line endings. I debugged this further with a Windows Host machine and a Ubuntu Hyper-V VM: I inserted the following Key Sequence:
The deltas produced and sent over the wire from windows are the following: [{"insert":"1"}]
[{"retain":1},{"insert":"2"}]
[{"retain":2},{"insert":"3"}]
[{"retain":3},{"insert":"\r\n"}]
[{"retain":5},{"insert":"\r\n"}]
[{"retain":5},{"delete":2}] The model text content on a windows patch receiver are the following: ["1"]
["1", "2"]
["1", "2", "3"]
["1", "2", "3", "\r", "\n"]
["1", "2", "3", "\r", "\n", "\r", "\n"]
["1", "2", "3", "\r", "\n"] However, on the Ubuntu machine the patch receiver model text content is the following: ["1"]
["1", "2"]
["1", "2", "3"]
["1", "2", "3", "\n"]
["1", "2", "3", "\n", "\n"]
["1", "2", "3", "\n", "\n"] It seems like there is now way to tell monaco to always use |
For reference, I inlined and adjusted the code over here: https://github.com/the-guild-org/schemehub/blob/567e24600de7786a0652130cb5aa8d417fa7c89d/lib/yMonaco.tsx and it seems like the issues are no longer present. |
Thanks for these hints! @n1ru4l & @chenyjade @n1ru4l What exactly does your fix do? I don't find documentation on the |
@dmonad It is impossible to set the EOL that should be used. You can only call Another possible solution would be to try translating line endings from each platform, which I tried but failed miserably. reference links: |
How did you fix the problem @n1ru4l? The file that includes your fix is too big for me to review entirely. Do you call |
https://github.com/the-guild-org/schemehub/blob/567e24600de7786a0652130cb5aa8d417fa7c89d/lib/yMonaco.tsx#L299-L303 I added those two lines for fixing the behavior. Not sure about other implications but seems to work fine in an environment with 4 concurrent cross-platform users. |
I can't say whether the fix works. It seems to work for @n1ru4l. I'm not sure whether I want to get this merged in. I hope there is a better solution than this. What is the collaborative VSCode editor doing, for example? Changing line endings to a specific format might lead to problems. E.g. we probably don't want to change line endings for Windows users that work on native files. I'm just a bit hesitant to merge this.. |
@dmonad, I have tried the fix and it definitely works, though this would require you to pass the monaco instance to the binding. https://github.com/yaralahruthik/y-monaco. Yet I have decided to move away from monaco editor to code mirror. As I feel code mirror is more robust solution for my needs. |
Until we find a fix for the bug, I found a solution that I think prevents Monaco from writing '\r': const editor = monaco.editor.create(document.getElementById("editor"), {
value:"",
language: "typescript",
});
// Note: there may be a way to update the existing model instead of swap it with a new one.
const newModel = monaco.editor.createModel("", "typescript");
newModel.setEOL(0); // Sets EOL to \n
editor.setModel(newModel); // Swap models |
Use editor.getModel().setEOL(0); |
When testing the demo (https://demos.yjs.dev/monaco/monaco.html) with a colleague, where he's on Windows+Firefox and I am on Mac+Arc(Chromium) we have a consistent offset between his and my browser window. Our edits show up in the wrong place with mine shifted multiple characters left and his multiple to the right. Based on the above ticket, should I just consider Yjs + Monaco as not working for cross-browser/platform collaboration? |
Attempting to set the EOL prior to creating the binding can cause the EOL to get reset due to y-monaco invoking |
Why there are no updates on it since last 10 months, is this issue got solved? for me this solution, is still not working! |
We also hit this issue recently; we had been using Looking at the code in this repo, I found that Lines 167 to 170 in 7cecd51
I updated those lines to the following on my local machine, and it seems to have fixed the issue for us. const ytextValue = ytext.toString()
if (monacoModel.getValue() !== ytextValue) {
const eol = monacoModel.getEndOfLineSequence();
monacoModel.setValue(ytextValue)
monacoModel.setEOL(eol);
} |
When setting eol, you implicitly change the length of the line-endings. This might break collaboration. Are you sure that editors with different line-endings still sync up correctly? |
It does depend on the assumption that the contents of the We do want to test more to be sure it fully works as expected, but at least that's my understanding of it. |
Do we have a working solution? I've tried with this, but the issue persists. |
@ijevtic Yes, we've had this patch running in production for a few months now, and it's been working fine. I don't know the details of the rest of your project, but there are two other things to check:
|
Checklist
Describe the bug
A clear and concise description of what the bug is.
The content is different under different operating systems. It seems that user under Win10 can see only a single new line when user under mac enter two new lines. Bug also appears after the syntax completion, see section below on how to reproduce. After some testing, the content under mac is the same as the content under Android and iOS, just different from the content under win10 and no matter which browser or computer we use.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
The content on both end should look the same.
Screenshots
If applicable, add screenshots to help explain your problem.
Screen shot from Windows:
Screenshot from Mac:
Environment Information
Browser / Node.js [e.g. Chrome, Firefox, Node.js]
Chrome 87.0.4280.88 on both win10 and Mac
Yjs version and the versions of the y-* modules you are using [e.g. yjs v13.0.1, y-webrtc v1.2.1]. Use
npm ls yjs
to find out the exact version you are using.[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: