1919import React , { Component , Fragment } from 'react'
2020import './jupyteredit.css'
2121
22- const jupyterurl = 'http://127.0.0.1:8000/jupyter/index.html'
23-
2422export class JupyterEdit extends Component {
2523 constructor ( props ) {
2624 super ( props )
@@ -32,13 +30,15 @@ export class JupyterEdit extends Component {
3230 }
3331
3432 componentDidMount ( ) {
33+ if ( ! this . props . jupyterurl ) throw new Error ( 'No jupyter url passed' )
3534 window . addEventListener ( 'message' , this . onMessage )
3635 if ( this . props . receiveInterceptorUpdate ) {
3736 this . activateInterceptor ( true )
3837 }
3938 }
4039
4140 componentDidUpdate ( prevProps ) {
41+ if ( ! this . props . jupyterurl ) throw new Error ( 'No jupyter url passed' )
4242 if ( this . props . appid !== prevProps . appid ) {
4343 this . activateApp ( )
4444 }
@@ -132,7 +132,9 @@ export class JupyterEdit extends Component {
132132 }
133133
134134 onMessage ( event ) {
135- if ( event . origin !== new URL ( jupyterurl ) . origin ) return
135+ if ( event . source === window ) return
136+ if ( event . source !== this . iframe . contentWindow ) return
137+ if ( event . origin !== new URL ( this . props . jupyterurl ) . origin ) return
136138 const data = event . data
137139 if ( event . data . requestId ) {
138140 const requestId = event . data . requestId
@@ -209,7 +211,8 @@ export class JupyterEdit extends Component {
209211 }
210212
211213 sendToIFrame ( message ) {
212- if ( this . iframe ) this . iframe . contentWindow . postMessage ( message , jupyterurl )
214+ if ( this . iframe )
215+ this . iframe . contentWindow . postMessage ( message , this . props . jupyterurl )
213216 }
214217
215218 async sendToIFrameAndReceive ( message ) {
@@ -255,7 +258,7 @@ export class JupyterEdit extends Component {
255258 < iframe
256259 style = { { width, height } }
257260 className = { className }
258- src = { jupyterurl || this . props . jupyterurl }
261+ src = { this . props . jupyterurl }
259262 ref = { ( el ) => {
260263 this . iframe = el
261264 } }
0 commit comments