Skip to content

Commit 221a4ba

Browse files
authored
Fix joining live session (codesandbox#2608)
The sandbox transform was not called for a sandbox that was received from a live session, this adds it
1 parent f79e141 commit 221a4ba

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

packages/app/src/app/overmind/effects/api/index.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { client } from 'app/graphql/client';
2323
import { LIST_TEMPLATES } from 'app/pages/Dashboard/queries';
2424

2525
import apiFactory, { Api, ApiConfig } from './apiFactory';
26+
import { transformSandbox } from '../utils/sandbox';
2627

2728
let api: Api;
2829

@@ -65,16 +66,7 @@ export default {
6566
const sandbox = await api.get<Sandbox>(`/sandboxes/${id}`);
6667

6768
// We need to add client side properties for tracking
68-
return {
69-
...sandbox,
70-
modules: sandbox.modules.map(module => ({
71-
...module,
72-
savedCode: null,
73-
isNotSynced: false,
74-
errors: [],
75-
corrections: [],
76-
})),
77-
};
69+
return transformSandbox(sandbox);
7870
},
7971
async forkSandbox(id: string, body?: unknown): Promise<Sandbox> {
8072
const url = id.includes('/')
@@ -83,16 +75,7 @@ export default {
8375

8476
const sandbox = await api.post<Sandbox>(url, body || {});
8577

86-
return {
87-
...sandbox,
88-
modules: sandbox.modules.map(module => ({
89-
...module,
90-
savedCode: null,
91-
isNotSynced: false,
92-
errors: [],
93-
corrections: [],
94-
})),
95-
};
78+
return transformSandbox(sandbox);
9679
},
9780
createModule(sandboxId: string, module: Module): Promise<Module> {
9881
return api.post(`/sandboxes/${sandboxId}/modules`, {

packages/app/src/app/overmind/effects/live/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@codesandbox/common/lib/types';
1313
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
1414
import clientsFactory from './clients';
15+
import { transformSandbox } from '../utils/sandbox';
1516

1617
type Options = {
1718
onApplyOperation(args: { moduleShortid: string; operation: any }): void;
@@ -107,9 +108,11 @@ export default {
107108
return new Promise((resolve, reject) => {
108109
channel
109110
.join()
110-
.receive('ok', resp =>
111-
resolve(camelizeKeys(resp) as JoinChannelResponse)
112-
)
111+
.receive('ok', resp => {
112+
const result = camelizeKeys(resp) as JoinChannelResponse;
113+
result.sandbox = transformSandbox(result.sandbox);
114+
resolve(result);
115+
})
113116
.receive('error', resp => reject(camelizeKeys(resp)));
114117
});
115118
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function transformSandbox(sandbox: Sandbox) {
2+
// We need to add client side properties for tracking
3+
return {
4+
...sandbox,
5+
modules: sandbox.modules.map(module => ({
6+
...module,
7+
savedCode: null,
8+
isNotSynced: false,
9+
errors: [],
10+
corrections: [],
11+
})),
12+
};
13+
}

0 commit comments

Comments
 (0)