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 101101 "browser-resolve" : " CompuIves/node-browser-resolve" ,
102102 "circular-json" : " ^0.4.0" ,
103103 "codemirror" : " ^5.27.4" ,
104- "codesandbox-api" : " 0.0.23 " ,
104+ "codesandbox-api" : " 0.0.24 " ,
105105 "codesandbox-import-utils" : " ^2.1.11" ,
106106 "color" : " ^0.11.4" ,
107107 "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';
88import { getModulePath } from '@codesandbox/common/lib/sandbox/modules' ;
99import { generateFileFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json' ;
1010import { 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' ;
1712import { show404 } from 'sandbox-hooks/not-found-screen' ;
1813
1914import compile , { getCurrentManager } from './compile' ;
@@ -68,10 +63,6 @@ requirePolyfills().then(() => {
6863 sendReady ( ) ;
6964
7065 if ( ! window . opener ) {
71- // Means we're in the editor
72- setupHistoryListeners ( ) ;
73- setupConsole ( ) ;
74- listenForPreviewSecret ( ) ;
7566 window . addEventListener ( 'message' , ( { data } ) => {
7667 switch ( data . type ) {
7768 case 'activate' :
Original file line number Diff line number Diff line change 11/* eslint-disable import/default */
22import BabelWorker from 'worker-loader?publicPath=/&name=babel-transpiler.[hash:8].worker.js!./eval/transpilers/babel/worker/index' ;
33/* 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' ;
47
58window . babelworkers = [ ] ;
69for ( let i = 0 ; i < 3 ; i ++ ) {
710 window . babelworkers . push ( new BabelWorker ( ) ) ;
811}
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 11{
22 "name" : " codesandbox-api" ,
3- "version" : " 0.0.23 " ,
3+ "version" : " 0.0.24 " ,
44 "description" : " " ,
55 "keywords" : [],
66 "repository" : {
Original file line number Diff line number Diff line change @@ -18,13 +18,24 @@ function checkIsStandalone() {
1818// Whether the tab has a connection with the editor
1919export const isStandalone = checkIsStandalone ( ) ;
2020
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+
2129// Field used by a "child" frame to determine its parent origin
2230let parentOrigin : string | null = null ;
2331
2432const parentOriginListener = ( e : MessageEvent ) => {
2533 if ( e . data . type === 'register-frame' ) {
2634 parentOrigin = e . data . origin ;
2735
36+ if ( initializeResolved ) {
37+ initializeResolved ( ) ;
38+ }
2839 self . removeEventListener ( 'message' , parentOriginListener ) ;
2940 }
3041} ;
Original file line number Diff line number Diff line change 5252 "@tippy.js/react" : " ^3.1.1" ,
5353 "babel-plugin-preval" : " ^3.0.1" ,
5454 "babel-plugin-transform-es2015-modules-commonjs" : " ^6.26.2" ,
55- "codesandbox-api" : " 0.0.23 " ,
55+ "codesandbox-api" : " 0.0.24 " ,
5656 "color" : " 0.11.4" ,
5757 "date-fns" : " ^2.0.0" ,
5858 "dot-object" : " 1.9.0" ,
Original file line number Diff line number Diff line change 3333 "@reach/auto-id" : " ^0.7.1" ,
3434 "@reach/visually-hidden" : " ^0.7.0" ,
3535 "@styled-system/css" : " ^5.1.4" ,
36- "codesandbox-api" : " 0.0.23 " ,
36+ "codesandbox-api" : " 0.0.24 " ,
3737 "color" : " 3.1.2" ,
3838 "date-fns" : " ^2.8.1" ,
3939 "react-router-dom" : " ^5.1.2" ,
Original file line number Diff line number Diff line change 2020 },
2121 "dependencies" : {
2222 "@codesandbox/common" : " ^1.0.8" ,
23- "codesandbox-api" : " 0.0.23 " ,
23+ "codesandbox-api" : " 0.0.24 " ,
2424 "debug" : " ^4.1.1" ,
2525 "socket.io-client" : " ^2.2.0"
2626 },
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' ;
22import Hook from 'console-feed/lib/Hook' ;
33import { Encode } from 'console-feed/lib/Transform' ;
44
55export default function setupConsole ( ) {
6- Hook ( window . console , log => {
6+ Hook ( window . console , async log => {
7+ await intializedPromise ;
78 dispatch ( {
89 type : 'console' ,
910 log,
Original file line number Diff line number Diff line change 1212 },
1313 "dependencies" : {
1414 "@codesandbox/common" : " ^1.0.8" ,
15- "codesandbox-api" : " 0.0.23 " ,
15+ "codesandbox-api" : " 0.0.24 " ,
1616 "console-feed" : " ^2.8.5" ,
1717 "react-dev-utils" : " 3.1.1"
1818 },
You can’t perform that action at this time.
0 commit comments