Skip to content

Commit b128cd9

Browse files
committed
Fix updating package.json with live
1 parent 12c2e11 commit b128cd9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export const onOperationApplied: Action<{
285285
return;
286286
}
287287

288-
actions.editor.internal.setModuleCode({
288+
actions.editor.internal.setStateModuleCode({
289289
module,
290290
code,
291291
});
@@ -316,28 +316,37 @@ export const codeChanged: Action<{
316316
return;
317317
}
318318

319-
if (state.live.isLive) {
320-
const operation = event
321-
? eventToTransform(event, module.code).operation
322-
: getTextOperation(module.code, code);
319+
// module.code !== code check is there to make sure that we don't end up sending
320+
// duplicate updates to live. module.code === code only when VSCode detected a change
321+
// from the filesystem (fs changed, vscode sees it, sends update). If this happens we
322+
// never want to send that code update, since this actual code change goes through this
323+
// specific code flow already.
324+
if (state.live.isLive && module.code !== code) {
325+
let operation;
326+
if (event) {
327+
operation = eventToTransform(event, code);
328+
} else {
329+
const transform = getTextOperation(module.code, code);
330+
331+
operation = transform.operation;
332+
}
323333

324334
effects.live.sendCodeUpdate(moduleShortid, operation);
325335
}
326336

327-
actions.editor.internal.setModuleCode({
337+
actions.editor.internal.setStateModuleCode({
328338
module,
329339
code,
330340
});
341+
if (module.savedCode !== null && module.code === module.savedCode) {
342+
effects.vscode.revertModule(module);
343+
}
331344

332345
const { isServer } = getTemplate(state.editor.currentSandbox.template);
333346

334347
if (!isServer && state.preferences.settings.livePreviewEnabled) {
335348
actions.editor.internal.updatePreviewCode();
336349
}
337-
338-
if (module.savedCode !== null && module.code === module.savedCode) {
339-
effects.vscode.revertModule(module);
340-
}
341350
};
342351

343352
export const saveClicked: AsyncAction = withOwnedSandbox(

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export const addNpmDependencyToPackageJson: AsyncAction<{
300300
});
301301
};
302302

303-
export const setModuleCode: Action<{
303+
export const setStateModuleCode: Action<{
304304
module: Module;
305305
code: string;
306306
}> = ({ state, effects }, { module, code }) => {

0 commit comments

Comments
 (0)