Skip to content

Commit 3d254d2

Browse files
committed
Remove static jupyterurl
1 parent a2e2f75 commit 3d254d2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/app.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,7 @@ class App extends Component {
28972897
>
28982898
<JupyterEdit
28992899
editActivated={this.state.jupyteredit}
2900+
jupyterurl={window.location.origin + '/jupyter/index.html'}
29002901
ref={this.jupyteredit}
29012902
document={this.state.jupyterDocument}
29022903
filename={this.state.jupyterFilename}

src/jupyteredit.jsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import React, { Component, Fragment } from 'react'
2020
import './jupyteredit.css'
2121

22-
const jupyterurl = 'http://127.0.0.1:8000/jupyter/index.html'
23-
2422
export 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

Comments
 (0)