File tree Expand file tree Collapse file tree 13 files changed +34
-21
lines changed Expand file tree Collapse file tree 13 files changed +34
-21
lines changed Original file line number Diff line number Diff line change 101
101
"browser-resolve" : " CompuIves/node-browser-resolve" ,
102
102
"circular-json" : " ^0.4.0" ,
103
103
"codemirror" : " ^5.27.4" ,
104
- "codesandbox-api" : " 0.0.23 " ,
104
+ "codesandbox-api" : " 0.0.24 " ,
105
105
"codesandbox-import-utils" : " ^2.1.11" ,
106
106
"color" : " ^0.11.4" ,
107
107
"compare-versions" : " ^3.1.0" ,
Original file line number Diff line number Diff line change @@ -8,12 +8,7 @@ import requirePolyfills from '@codesandbox/common/lib/load-dynamic-polyfills';
8
8
import { getModulePath } from '@codesandbox/common/lib/sandbox/modules' ;
9
9
import { generateFileFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json' ;
10
10
import { getSandboxId } from '@codesandbox/common/lib/utils/url-generator' ;
11
- import setupConsole from 'sandbox-hooks/console' ;
12
- import setupHistoryListeners from 'sandbox-hooks/url-listeners' ;
13
- import {
14
- listenForPreviewSecret ,
15
- getPreviewSecret ,
16
- } from 'sandbox-hooks/preview-secret' ;
11
+ import { getPreviewSecret } from 'sandbox-hooks/preview-secret' ;
17
12
import { show404 } from 'sandbox-hooks/not-found-screen' ;
18
13
19
14
import compile , { getCurrentManager } from './compile' ;
@@ -68,10 +63,6 @@ requirePolyfills().then(() => {
68
63
sendReady ( ) ;
69
64
70
65
if ( ! window . opener ) {
71
- // Means we're in the editor
72
- setupHistoryListeners ( ) ;
73
- setupConsole ( ) ;
74
- listenForPreviewSecret ( ) ;
75
66
window . addEventListener ( 'message' , ( { data } ) => {
76
67
switch ( data . type ) {
77
68
case 'activate' :
Original file line number Diff line number Diff line change 1
1
/* eslint-disable import/default */
2
2
import BabelWorker from 'worker-loader?publicPath=/&name=babel-transpiler.[hash:8].worker.js!./eval/transpilers/babel/worker/index' ;
3
3
/* eslint-enable import/default */
4
+ import hookConsole from 'sandbox-hooks/console' ;
5
+ import setupHistoryListeners from 'sandbox-hooks/url-listeners' ;
6
+ import { listenForPreviewSecret } from 'sandbox-hooks/preview-secret' ;
4
7
5
8
window . babelworkers = [ ] ;
6
9
for ( let i = 0 ; i < 3 ; i ++ ) {
7
10
window . babelworkers . push ( new BabelWorker ( ) ) ;
8
11
}
12
+
13
+ if ( ! window . opener ) {
14
+ // Means we're in the editor
15
+ setupHistoryListeners ( ) ;
16
+ hookConsole ( ) ;
17
+ listenForPreviewSecret ( ) ;
18
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " codesandbox-api" ,
3
- "version" : " 0.0.23 " ,
3
+ "version" : " 0.0.24 " ,
4
4
"description" : " " ,
5
5
"keywords" : [],
6
6
"repository" : {
Original file line number Diff line number Diff line change @@ -18,13 +18,24 @@ function checkIsStandalone() {
18
18
// Whether the tab has a connection with the editor
19
19
export const isStandalone = checkIsStandalone ( ) ;
20
20
21
+ let initializeResolved : ( ) => void ;
22
+ /**
23
+ * Resolves when the handshake between the frame and the editor has succeeded
24
+ */
25
+ export const intializedPromise = new Promise ( resolve => {
26
+ initializeResolved = resolve ;
27
+ } ) ;
28
+
21
29
// Field used by a "child" frame to determine its parent origin
22
30
let parentOrigin : string | null = null ;
23
31
24
32
const parentOriginListener = ( e : MessageEvent ) => {
25
33
if ( e . data . type === 'register-frame' ) {
26
34
parentOrigin = e . data . origin ;
27
35
36
+ if ( initializeResolved ) {
37
+ initializeResolved ( ) ;
38
+ }
28
39
self . removeEventListener ( 'message' , parentOriginListener ) ;
29
40
}
30
41
} ;
Original file line number Diff line number Diff line change 52
52
"@tippy.js/react" : " ^3.1.1" ,
53
53
"babel-plugin-preval" : " ^3.0.1" ,
54
54
"babel-plugin-transform-es2015-modules-commonjs" : " ^6.26.2" ,
55
- "codesandbox-api" : " 0.0.23 " ,
55
+ "codesandbox-api" : " 0.0.24 " ,
56
56
"color" : " 0.11.4" ,
57
57
"date-fns" : " ^2.0.0" ,
58
58
"dot-object" : " 1.9.0" ,
Original file line number Diff line number Diff line change 33
33
"@reach/auto-id" : " ^0.7.1" ,
34
34
"@reach/visually-hidden" : " ^0.7.0" ,
35
35
"@styled-system/css" : " ^5.1.4" ,
36
- "codesandbox-api" : " 0.0.23 " ,
36
+ "codesandbox-api" : " 0.0.24 " ,
37
37
"color" : " 3.1.2" ,
38
38
"date-fns" : " ^2.8.1" ,
39
39
"react-router-dom" : " ^5.1.2" ,
Original file line number Diff line number Diff line change 20
20
},
21
21
"dependencies" : {
22
22
"@codesandbox/common" : " ^1.0.8" ,
23
- "codesandbox-api" : " 0.0.23 " ,
23
+ "codesandbox-api" : " 0.0.24 " ,
24
24
"debug" : " ^4.1.1" ,
25
25
"socket.io-client" : " ^2.2.0"
26
26
},
Original file line number Diff line number Diff line change 1
- import { dispatch , listen } from 'codesandbox-api' ;
1
+ import { dispatch , listen , intializedPromise } from 'codesandbox-api' ;
2
2
import Hook from 'console-feed/lib/Hook' ;
3
3
import { Encode } from 'console-feed/lib/Transform' ;
4
4
5
5
export default function setupConsole ( ) {
6
- Hook ( window . console , log => {
6
+ Hook ( window . console , async log => {
7
+ await intializedPromise ;
7
8
dispatch ( {
8
9
type : 'console' ,
9
10
log,
Original file line number Diff line number Diff line change 12
12
},
13
13
"dependencies" : {
14
14
"@codesandbox/common" : " ^1.0.8" ,
15
- "codesandbox-api" : " 0.0.23 " ,
15
+ "codesandbox-api" : " 0.0.24 " ,
16
16
"console-feed" : " ^2.8.5" ,
17
17
"react-dev-utils" : " 3.1.1"
18
18
},
Original file line number Diff line number Diff line change 13
13
"build:dev" : " rollup -c rollup.config.js"
14
14
},
15
15
"dependencies" : {
16
- "codesandbox-api" : " 0.0.23 "
16
+ "codesandbox-api" : " 0.0.24 "
17
17
},
18
18
"devDependencies" : {
19
19
"@babel/core" : " ^7.5.5" ,
Original file line number Diff line number Diff line change 76
76
"@types/shelljs" : " ^0.8.0" ,
77
77
"classnames" : " ^2.2.5" ,
78
78
"codemirror" : " ^5.35.0" ,
79
- "codesandbox-api" : " 0.0.23 " ,
79
+ "codesandbox-api" : " 0.0.24 " ,
80
80
"codesandbox-import-utils" : " ^1.2.3" ,
81
81
"react-broadcast" : " ^0.6.2" ,
82
82
"react-codemirror2" : " ^4.0.1" ,
Original file line number Diff line number Diff line change 65
65
"testRegex" : " (/__tests__/.*|\\ .(test|spec))\\ .(ts|tsx|js)$"
66
66
},
67
67
"dependencies" : {
68
- "codesandbox-api" : " 0.0.23 " ,
68
+ "codesandbox-api" : " 0.0.24 " ,
69
69
"codesandbox-import-utils" : " ^1.2.3" ,
70
70
"lodash.isequal" : " ^4.5.0"
71
71
},
You can’t perform that action at this time.
0 commit comments