Skip to content

Commit 5c38c63

Browse files
committed
fixes #154 views do not redisplay on refresh in Jupyter Notebook
1 parent b9a0cdf commit 5c38c63

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

idom/widgets/display.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
from typing import Any
44
from urllib.parse import urlparse
5-
from IPython import display as _ipy_display
65

76

87
def display(kind: str, *args: Any, **kwargs: Any) -> Any:
@@ -31,29 +30,26 @@ def __init__(self, url: str) -> None:
3130
{"host": parsed_url.netloc, "protocol": parsed_url.scheme + ":"}
3231
)
3332
self._path = parsed_url.path
34-
_ipy_display.display_html(
35-
"<script>document.idomServerExists = true;</script>", raw=True,
36-
)
3733

3834
def _script(self, mount_id):
3935
return f"""
4036
<script type="module">
37+
const loc = {self._location};
38+
const idom_url = "//" + loc.host + "{self._path}";
39+
const http_proto = loc.protocol;
40+
const ws_proto = (http_proto === "https:") ? "wss:" : "ws:";
4141
// we want to avoid making this request (in case of CORS)
4242
// unless we know an IDOM server is expected to respond
43-
if (document.idomServerExists) {{
44-
const loc = {self._location};
45-
const idom_url = "//" + loc.host + "{self._path}";
46-
const http_proto = loc.protocol;
47-
const ws_proto = (http_proto === "https:") ? "wss:" : "ws:";
43+
fetch(http_proto + idom_url, {{mode: "no-cors"}}).then(rsp => {{
4844
import(http_proto + idom_url + "/client/core_modules/layout.js").then(
4945
(module) => {{
50-
module.renderLayout(
51-
document.getElementById("{mount_id}"),
52-
ws_proto + idom_url + "/stream"
53-
);
46+
module.renderLayout(
47+
document.getElementById("{mount_id}"),
48+
ws_proto + idom_url + "/stream"
49+
);
5450
}}
5551
);
56-
}}
52+
}});
5753
</script>
5854
"""
5955

0 commit comments

Comments
 (0)