Skip to content

WASM canvas resize: skip with_surface_size on wasm (alt to #431)#432

Merged
nicoburns merged 1 commit into
DioxusLabs:mainfrom
tonybierman:experiment/wasm-no-surface-size
May 12, 2026
Merged

WASM canvas resize: skip with_surface_size on wasm (alt to #431)#432
nicoburns merged 1 commit into
DioxusLabs:mainfrom
tonybierman:experiment/wasm-no-surface-size

Conversation

@tonybierman
Copy link
Copy Markdown
Contributor

Alternative to #431 implementing @nicoburns's hypothesis: drop .with_surface_size(...) on wasm so winit-web never writes inline canvas.style.width/height, letting host CSS size the canvas directly — no style-stripping needed. Same wgpu surface.configure debounce as #431 (with timer coalescing to avoid closure leaks during drag), plus a fallback that seeds the initial size from the canvas's CSS layout when winit-web reports 0×0 at init.

…#431)

Alternative implementation of Nico's hypothesis on DioxusLabs#431. Instead of
stripping the inline `canvas.style.width/height` that winit-web writes,
drop the `.with_surface_size(...)` call on wasm entirely so the styles
never get set in the first place. Host CSS controls the canvas box.

Three pieces in one branch:
- Examples (seven_guis, todomvc, wasm_hello) no longer call
  `.with_surface_size(...)` on wasm; the seven_guis and todomvc
  `index.html` files get `canvas { width: 100%; height: 100% }` so the
  canvas fills the viewport once winit isn't pinning it.
- `View::init` falls back to reading the canvas's CSS layout box
  (`offset_width × offset_height × devicePixelRatio`) when winit-web's
  initial `surface_size()` is 0×0 — without this, wgpu fails with a
  swapchain-size-0 error before the first ResizeObserver fires.
- Same wgpu `surface.configure` debounce as DioxusLabs#431, with a coalesce guard
  so a continuous browser-window drag schedules one timer instead of
  one per `SurfaceResized`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tonybierman
Copy link
Copy Markdown
Contributor Author

@nicoburns request review

@nicoburns nicoburns merged commit 3e0142f into DioxusLabs:main May 12, 2026
16 checks passed
@tonybierman tonybierman deleted the experiment/wasm-no-surface-size branch May 12, 2026 13:35
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.

2 participants