Skip to content

Commit 8e2751c

Browse files
authored
Fix live syncing issues (codesandbox#1832)
There were two big problems with the current live implementation: 1. We camelized keys in module sync, and the keys for shortids. So sometimes the wrong modules got synced back 2. Adding a dependency called changeCode two times, which caused an operation mismatch 3. For applyClient we didn't do an automatic repair, it could even crash the whole editor This PR fixes those issues
1 parent cc0b3c8 commit 8e2751c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

docker/run-docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33
yarn
4-
yarn run start:dev_api
4+
NODE_OPTIONS=--max_old_space_size=8192 yarn run start:dev_api

packages/app/src/app/store/modules/editor/sequences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const saveCode = [
210210
ensureOwnedEditable,
211211
when(state`preferences.settings.experimentVSCode`),
212212
{
213-
true: [changeCode],
213+
true: [],
214214
false: [
215215
when(state`preferences.settings.prettifyOnSaveEnabled`),
216216
{

packages/app/src/app/store/modules/live/actions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function listen({ props, live }) {
3131

3232
export function consumeModuleState({ props }) {
3333
return {
34-
moduleState: camelizeKeys(props.data.module_state),
34+
moduleState: props.data.module_state,
3535
};
3636
}
3737

@@ -363,11 +363,22 @@ export function updateModule({ props, state }) {
363363
);
364364
}
365365

366-
export function sendTransform({ ot, props }) {
366+
export function sendTransform({ ot, props, live }) {
367367
if (!props.operation) {
368368
return {};
369369
}
370-
ot.applyClient(props.moduleShortid, props.operation);
370+
371+
try {
372+
ot.applyClient(props.moduleShortid, props.operation);
373+
} catch (e) {
374+
// Something went wrong, probably a sync mismatch. Request new version
375+
console.error(
376+
'Something went wrong with applying OT operation',
377+
props.moduleShortid,
378+
props.operation
379+
);
380+
live.send('live:module_state', {});
381+
}
371382

372383
return {};
373384
}

0 commit comments

Comments
 (0)