Skip to content

Commit 8fc41ff

Browse files
christianalfoniCompuIves
authored andcommitted
do smooth forking, but restart executor and refresh preview (codesandbox#3170)
1 parent 3f481fa commit 8fc41ff

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,7 @@ export const setCurrentSandbox: AsyncAction<Sandbox> = async (
261261
state.workspace.project.description = sandbox.description || '';
262262
state.workspace.project.alias = sandbox.alias || '';
263263

264-
await effects.executor.initializeExecutor(sandbox);
265-
266-
[
267-
'connect',
268-
'disconnect',
269-
'sandbox:status',
270-
'sandbox:start',
271-
'sandbox:stop',
272-
'sandbox:error',
273-
'sandbox:log',
274-
'sandbox:hibernate',
275-
'sandbox:update',
276-
'sandbox:port',
277-
'shell:out',
278-
'shell:exit',
279-
].forEach(message => {
280-
effects.executor.listen(message, actions.server.onSSEMessage);
281-
});
282-
283-
effects.executor.setupExecutor();
264+
actions.server.startContainer(sandbox);
284265
};
285266

286267
export const updateCurrentSandbox: AsyncAction<Sandbox> = async (

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ export const forkSandbox: AsyncAction<{
360360
);
361361
effects.preview.updateAddressbarUrl();
362362

363+
if (templateDefinition.isServer) {
364+
effects.preview.refresh();
365+
actions.server.startContainer(forkedSandbox);
366+
}
367+
363368
if (state.workspace.openedWorkspaceItem === 'project-summary') {
364369
actions.workspace.openDefaultItem();
365370
}

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Action } from 'app/overmind';
1+
import { ViewTab } from '@codesandbox/common/lib/templates/template';
22
import {
3-
ServerStatus,
3+
Sandbox,
44
ServerContainerStatus,
55
ServerPort,
6+
ServerStatus,
67
} from '@codesandbox/common/lib/types';
78
import { NotificationStatus } from '@codesandbox/notifications/lib/state';
9+
import { Action, AsyncAction } from 'app/overmind';
810
import { getDevToolsTabPosition } from 'app/overmind/utils/server';
9-
import { ViewTab } from '@codesandbox/common/lib/templates/template';
1011

1112
export const restartSandbox: Action = ({ effects }) => {
1213
effects.executor.emit('sandbox:restart');
@@ -222,3 +223,29 @@ export const onBrowserFromPortOpened: Action<{
222223
});
223224
}
224225
};
226+
227+
export const startContainer: AsyncAction<Sandbox> = async (
228+
{ effects, actions },
229+
sandbox
230+
) => {
231+
await effects.executor.initializeExecutor(sandbox);
232+
233+
[
234+
'connect',
235+
'disconnect',
236+
'sandbox:status',
237+
'sandbox:start',
238+
'sandbox:stop',
239+
'sandbox:error',
240+
'sandbox:log',
241+
'sandbox:hibernate',
242+
'sandbox:update',
243+
'sandbox:port',
244+
'shell:out',
245+
'shell:exit',
246+
].forEach(message => {
247+
effects.executor.listen(message, actions.server.onSSEMessage);
248+
});
249+
250+
await effects.executor.setupExecutor();
251+
};

0 commit comments

Comments
 (0)