Skip to content

feat(web): support multi-canvas Rune islands on a single DOM page (#2553) - #3257

Merged
Hona merged 1 commit into
devfrom
feat/web-multi-canvas-islands
Dec 2, 2026
Merged

Hona merged 1 commit into
devfrom
feat/web-multi-canvas-islands

Conversation

@Hona

@Hona Hona commented Dec 2, 2026

Copy link
Copy Markdown
Member

Fixes #2553

Summary

Adds additive multi-canvas web island support so a single Rune app or WASM module can mount into multiple <canvas> elements on one DOM page while leaving the existing single-canvas App::run / App::canvas_id default behavior unchanged.

Design & Changes

  • Additive multi-island API (cross-platform compiling, no pub fields added to literal-built types):
    • App::web_island(canvas_id, view), App::web_island_with(WebIsland<S>), and AppHandle::mount_web_island(WebIsland<S>) mount additional islands sharing state S.
    • WindowSpec::canvas_id(id) (with App::window), rune::web::mount_island(canvas_id, app), and distinct inline App::canvas_id(...).try_run() calls mount independent-state islands onto the page's shared winit event loop.
    • IslandHandle (canvas_id, is_mounted, request_redraw, unmount) tears down only its target island—releasing DOM listeners, ResizeObserver, frame/timer wakes, canvas surface, borrowed attributes/styles, and [data-rune-a11y] mirror—without disturbing sibling islands.
  • Shared-state dirty fan-out (crates/rune/src/platform/web_math/islands.rs):
    • SharedStateCell<S> + SharedDriver track mutable state access (states, poll returning true, key/focus/IME hooks, AppHandle::update) while keeping read-only ViewDriver::view rebuilds and Tx::live_only handlers out of mutation fan-out, so mutating S in Island A marks Island B dirty and schedules its redraw with zero ping-pong.
  • Shared WebGPU device & per-canvas WebGL2 (crates/rune/src/platform/web/islands.rs):
    • Reuses one BrowserWebGpu Gpu device across sibling canvas surfaces (destroying the device only when the shared loop exits), while keeping per-canvas WebGL2 devices isolated and destroyed on single-island unmount.
  • Per-canvas DOM/a11y isolation (crates/rune/src/platform/web/bridge.js):
    • Unique per-instance rune-focus-<id>-{0,1} focus proxy IDs (no duplicate IDs across islands).
    • Per-canvas ResizeObserver syncing embedded [data-rune-a11y] and [data-rune-web-images] boxes to each canvas's offset rect so sibling canvases inside a shared parent never overlap mirrors, tagged with data-rune-canvas-id.
    • Scoped document copy handling and automation-mode textbox focus checks strictly to the owning island, and cleaned up ResizeObserver, live regions, focus proxies, and selection-pick style elements in destroy(h).

Verification

  • node --test crates/rune/src/platform/web/bridge.test.mjs (97/97 pass, including new 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 in platform::web_math::islands::tests)
  • cargo check -j 1 -p rune --lib, cargo check -j 1 -p rune --target wasm32-unknown-unknown, and cargo check -j 1 -p rune --target wasm32-unknown-unknown --features webgl
  • scripts/file-size.sh (0 errors, 0 folder-shape warnings, no new files over 800 lines)
  • Not run locally: live multi-canvas interactive WebGPU/WebGL2 browser page verification.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 05:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Hona
Hona force-pushed the feat/web-multi-canvas-islands branch from dc303c1 to c9e0632 Compare December 2, 2026 05:56
@Hona
Hona merged commit 40eb4ae into dev Dec 2, 2026
7 checks passed
@Hona
Hona deleted the feat/web-multi-canvas-islands branch December 2, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web: draw one app into more than one page canvas, so a DOM page can hold several Rune islands

2 participants