Skip to content

Commit 4e559f1

Browse files
committed
Fix forking a dirty sandbox
1 parent 3d725b7 commit 4e559f1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import { convertAuthorizationToPermissionType } from 'app/utils/authorization';
3333
import { clearCorrectionsFromAction } from 'app/utils/corrections';
3434
import history from 'app/utils/history';
35+
import { getSavedCode } from 'app/overmind/utils/sandbox';
3536
import { json } from 'overmind';
3637

3738
import eventToTransform from '../../utils/event-to-transform';
@@ -88,6 +89,20 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
8889
state.editor.currentSandbox
8990
);
9091

92+
// We now need to send all dirty files that came over from the last sandbox.
93+
// There is the scenario where you edit a file and press fork. Then the server
94+
// doesn't know about how you got to that dirty state.
95+
const changedModules = state.editor.currentSandbox.modules.filter(
96+
m => getSavedCode(m.code, m.savedCode) !== m.code
97+
);
98+
changedModules.forEach(m => {
99+
// Update server with latest data
100+
effects.live.sendCodeUpdate(
101+
m.shortid,
102+
getTextOperation(m.savedCode || '', m.code || '')
103+
);
104+
});
105+
91106
state.editor.isForkingSandbox = false;
92107
return;
93108
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ export const forkSandbox: AsyncAction<{
391391

392392
return {
393393
...module,
394+
savedCode: foundEquivalentModule.savedCode,
394395
code: foundEquivalentModule.code,
395396
};
396397
}),

0 commit comments

Comments
 (0)