statamic / collaboration

Real-time, multi-user editing with Statamic via websockets
https://statamic.com/addons/statamic/collaboration
33 stars 13 forks source link

Data loss due to Pusher error #50

Closed helloiamlukas closed 3 years ago

helloiamlukas commented 3 years ago

Bug

When having a large document, live updates are chunked. The size of the chunk is set to 8000 characters.

https://github.com/statamic/collaboration/blob/ecb520091fa812ae122d8e2b99d88ff8758a9803/resources/js/Workspace.js#L381

In certain cases this causes updates not to be broadcasted, as the maximum message size of 10kb is exceeded. This error neither shows up in the editor, nor in the console.

This can lead to data loss: As editors will not be able to see changes by others, they might overwrite their content by saving the document.

By turning on Pusher logs via Pusher.logToConsole = true; it is possible to see the full error message

Pusher : Event recd : {"event":"pusher:error","data":{"code":null,"message":"The data content of this event exceeds the allowed maximum (10240 bytes). See https://pusher.com/docs/channels/server_api/http-api#publishing-events for more info"}}

Solution

An easy solution for this would be to decrease the chunk size. https://github.com/statamic/collaboration/blob/ecb520091fa812ae122d8e2b99d88ff8758a9803/resources/js/Workspace.js#L381 Since one character can have up to 4 bytes, the safest would be to set the chunk size from 8000 to 2500.