You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Web: draw one app into more than one page canvas, so a DOM page can hold several Rune islands #2553
Context: a page that is mostly DOM shows two or three Rune views, each in its own <canvas> (for example a long list in one part of a page and a board in another). App::canvas_id mounts one app inline, but a second app on the same page fails at try_run:
a Rune app is already running on this page; call its AppHandle::quit before starting another
Environment: Rune dev at 048528dc, Chrome 159 on macOS, wasm32-unknown-unknown, wasm-bindgen 0.2.129.
What happens
// Two islands in one page: <canvas id="list"> and <canvas id="board">.App::new(list_spec).canvas_id("list").try_run()?;// OkApp::new(board_spec).canvas_id("board").try_run()?;// Err(BUSY)
The limit is in crates/rune/src/platform/web/page.rs#L21 (winit allows one event loop per page), and WEB.md#L134 says "One app runs per page at a time". On web, App::window requests are ignored (WEB.md#L423), so one app cannot draw into a second canvas either.
Ask
Let one web app draw into more than one page canvas: for example, App::window(WindowSpec) with a canvas_id, so each extra window binds an existing <canvas> and shares the app's event loop and GPU device. One GPU device and one glyph atlas for all canvases would also keep the memory of N islands close to the memory of one.
Workaround today
One app per page, with one canvas. A page with several islands must put them in one canvas, or mount and quit apps as the user moves between parts of the page.
confirmed in crates/rune/src/platform/web/page.rs (BUSY rejects a second app), crates/rune/src/platform/web/app.rs (PendingApp::check rejects extra windows and windowless), crates/rune/src/window/event_loop.rs (run_windows errors on wasm32), and crates/rune/src/window/spec.rs (WindowSpec does not forward canvas_id and open_window is not drained on web). winit's web backend already tracks multiple canvases by WindowId in one event loop, so sharing one loop and one webgpu Gpu device across canvases is feasible, though platform/web.rs and bridge.js currently assume one Running instance.
two design choices need a call before building:
api and island lifecycle: should islands use the multi-window api (WindowSpec::canvas_id with App::window, run_windows, and dynamic open_window / WindowHandle::close, leaving WindowSpec without canvas_id for in-canvas windows in Web: open_window and overlays draw as in-canvas windows instead of being ignored #1322), or should separate App::new(spec).canvas_id(...).try_run() calls share one page event loop so each dom island mounts and unmounts with its own AppHandle::quit?
webgl2 and glyph-atlas scope: on webgpu one Gpu device can drive multiple canvas surfaces, whereas webgl2 (crates/rune/src/platform/web/gpu.rs) binds one context and device per canvas, and rune currently owns TextSystem::atlas and Renderer per window even on desktop. should v1 share the event loop and webgpu Gpu device (with per-canvas webgl2 devices, or webgpu-only) and leave cross-window glyph-atlas sharing as separate work?
Additive multi-canvas islands, single-canvas default unchanged:App::run / App::canvas_id single-canvas behavior is unchanged. Multi-canvas DOM pages can now mount shared-state islands via App::web_island / App::web_island_with / AppHandle::mount_web_island (using WebIsland<S>), or independent-state islands via WindowSpec::canvas_id (with App::window), rune::web::mount_island, or distinct inline App::canvas_id(...).try_run() calls.
Shared-state dirty fan-out: Islands sharing state S run independent retained trees over one SharedStateCell<S>; mutating S in one island (or via AppHandle::update) automatically invalidates and schedules redraws on sibling islands without ping-ponging on read-only view rebuilds or Tx::live_only handlers.
Isolated per-canvas DOM bridge & clean unmount:bridge.js scopes [data-rune-a11y] mirrors (tagged with data-rune-canvas-id and aligned via a per-canvas ResizeObserver), unique rune-focus-<id>-{0,1} focus proxies, copy listeners, and automation textboxes per mounted canvas. IslandHandle::unmount() releases that island's listeners, ResizeObserver, canvas surface, borrowed attributes/styles, and a11y mirror without disturbing sibling islands.
GPU device scope: On WebGPU, sibling islands share one BrowserWebGpuGpu device across per-canvas surfaces (destroyed only when the shared loop exits); on WebGL2, each canvas owns and tears down its own context/device independently.
Verified locally:
node --test crates/rune/src/platform/web/bridge.test.mjs (100/100 pass, including multi-island isolation, focus handoff, automation textbox isolation, and clean unmount tests)
cargo test -j 1 -p rune --lib web (247/247 pass, including 6 new shared-state island and registry unit tests)
Not run locally: A live multi-canvas WebGPU/WebGL2 browser page was not exercised interactively on real browser GPU hardware. Please reopen if you hit any multi-canvas rendering, DPR, or focus edge case in a live browser.
Activity
opencodejr commentedon Nov 27, 2026
confirmed in
crates/rune/src/platform/web/page.rs(BUSYrejects a second app),crates/rune/src/platform/web/app.rs(PendingApp::checkrejects extra windows andwindowless),crates/rune/src/window/event_loop.rs(run_windowserrors on wasm32), andcrates/rune/src/window/spec.rs(WindowSpecdoes not forwardcanvas_idandopen_windowis not drained on web). winit's web backend already tracks multiple canvases byWindowIdin one event loop, so sharing one loop and one webgpuGpudevice across canvases is feasible, thoughplatform/web.rsandbridge.jscurrently assume oneRunninginstance.two design choices need a call before building:
WindowSpec::canvas_idwithApp::window,run_windows, and dynamicopen_window/WindowHandle::close, leavingWindowSpecwithoutcanvas_idfor in-canvas windows in Web: open_window and overlays draw as in-canvas windows instead of being ignored #1322), or should separateApp::new(spec).canvas_id(...).try_run()calls share one page event loop so each dom island mounts and unmounts with its ownAppHandle::quit?Gpudevice can drive multiple canvas surfaces, whereas webgl2 (crates/rune/src/platform/web/gpu.rs) binds one context and device per canvas, and rune currently ownsTextSystem::atlasandRendererper window even on desktop. should v1 share the event loop and webgpuGpudevice (with per-canvas webgl2 devices, or webgpu-only) and leave cross-window glyph-atlas sharing as separate work?feat(web): support multi-canvas Rune islands on a single DOM page (#2553
feat(web): support multi-canvas Rune islands on a single DOM page (#2553
Hona commentedon Dec 2, 2026
Shipped in #3257 (
40eb4ae5b).Design decisions:
App::run/App::canvas_idsingle-canvas behavior is unchanged. Multi-canvas DOM pages can now mount shared-state islands viaApp::web_island/App::web_island_with/AppHandle::mount_web_island(usingWebIsland<S>), or independent-state islands viaWindowSpec::canvas_id(withApp::window),rune::web::mount_island, or distinct inlineApp::canvas_id(...).try_run()calls.Srun independent retained trees over oneSharedStateCell<S>; mutatingSin one island (or viaAppHandle::update) automatically invalidates and schedules redraws on sibling islands without ping-ponging on read-only view rebuilds orTx::live_onlyhandlers.bridge.jsscopes[data-rune-a11y]mirrors (tagged withdata-rune-canvas-idand aligned via a per-canvasResizeObserver), uniquerune-focus-<id>-{0,1}focus proxies, copy listeners, and automation textboxes per mounted canvas.IslandHandle::unmount()releases that island's listeners,ResizeObserver, canvas surface, borrowed attributes/styles, and a11y mirror without disturbing sibling islands.BrowserWebGpuGpudevice across per-canvas surfaces (destroyed only when the shared loop exits); on WebGL2, each canvas owns and tears down its own context/device independently.Verified locally:
node --test crates/rune/src/platform/web/bridge.test.mjs(100/100 pass, including multi-island isolation, focus handoff, automation textbox isolation, and clean unmount tests)cargo test -j 1 -p rune --lib web(247/247 pass, including 6 new shared-state island and registry unit tests)cargo check -j 1 -p rune --lib,cargo check -j 1 -p rune --target wasm32-unknown-unknown, andcargo check -j 1 -p rune --target wasm32-unknown-unknown --features webglscripts/file-size.sh(0 errors, 0 folder-shape warnings)Not run locally: A live multi-canvas WebGPU/WebGL2 browser page was not exercised interactively on real browser GPU hardware. Please reopen if you hit any multi-canvas rendering, DPR, or focus edge case in a live browser.