Skip to content

Commit 18e0de9

Browse files
committed
Fix communication with sandbox after a fork
1 parent 751dd5d commit 18e0de9

File tree

2 files changed

+8
-1
lines changed
  • packages

2 files changed

+8
-1
lines changed

packages/app/src/app/components/Preview/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import * as React from 'react';
33
import type { Sandbox, Module } from 'common/types';
4-
import { listen, dispatch, registerFrame } from 'codesandbox-api';
4+
import { listen, dispatch, registerFrame, resetState } from 'codesandbox-api';
55
import { debounce } from 'lodash-es';
66
import io from 'socket.io-client';
77

@@ -334,6 +334,8 @@ class BasePreview extends React.Component<Props, State> {
334334
handleSandboxChange = (newId: string) => {
335335
this.serverPreview = getTemplate(this.props.sandbox.template).isServer;
336336

337+
resetState();
338+
337339
const url = this.serverPreview
338340
? getSSEUrl(newId)
339341
: frameUrl(newId, this.props.initialPath || '');

packages/codesandbox-api/src/dispatcher/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const parentOriginListener = (e: MessageEvent) => {
1919

2020
self.addEventListener('message', parentOriginListener);
2121

22+
export function resetState() {
23+
parentOrigin = null;
24+
bundlers.clear();
25+
}
26+
2227
/**
2328
* Send a message to the editor, this is most probably an action you generated
2429
*

0 commit comments

Comments
 (0)