Commit 8631282
authored
Fix env.render(mode="ipython") in Jupyter after Vite refactor (#1305)
PR #1152 wired vite-built visualizers into html_renderer() but the
notebook render path still didn't work — env.render(mode="ipython")
produced a blank iframe.
Two things were broken:
1. get_player() in kaggle_environments/utils.py treated the full HTML
document returned by html_renderer() as a JS snippet and spliced it into
static/player.html via renderer.strip(), producing a garbage page. Add a
third branch that detects a full HTML document (leading "<") and injects
`<script>window.kaggle = {...};</script>` before </head> instead.
2. web/core/src/player/player.ts::loadData() only accepted initial
replay data from HMR state, VITE_REPLAY_FILE, or postMessage. A notebook
iframe uses srcdoc with no parent script, so nothing ever posted →
visualizer sat at "Loading..." forever. Add a window.kaggle initial-data
source alongside the existing tiers, reusing the same agent-derivation
as the VITE_REPLAY_FILE branch.
The static/player.html fallback path is untouched — envs that still ship
a single-file JS renderer (orbit_wars) continue to work exactly as
before. GCS-served visualizers are unaffected: window.kaggle is only
injected in the Python get_player() call path.
Verified end-to-end: rebuilt connectx, rendered via
env.render(mode="html"), embedded via srcdoc in a browser — the board
renders, the yellow chip appears on step 2, playback controls populate
1/10 steps.
Bump version to 1.31.0.1 parent 8c8ace4 commit 8631282
3 files changed
Lines changed: 36 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
244 | 260 | | |
245 | 261 | | |
246 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
96 | 114 | | |
97 | 115 | | |
98 | 116 | | |
| |||
0 commit comments