Skip to content

fix: prevent viewport-height units from causing canvas rendering issues#148

Merged
tristan-mouchet merged 4 commits intodevelopfrom
fix/canvas-screen-units
Apr 10, 2026
Merged

fix: prevent viewport-height units from causing canvas rendering issues#148
tristan-mouchet merged 4 commits intodevelopfrom
fix/canvas-screen-units

Conversation

@tristan-mouchet
Copy link
Copy Markdown
Collaborator

@tristan-mouchet tristan-mouchet commented Apr 9, 2026

Summary

Viewport-height CSS units (vh, svh, dvh, lvh) caused a feedback loop on the canvas and preview: the iframe expanded to fit content, layers using these units grew with it, inflating the measured height indefinitely.
This also caused blank space in the preview when switching zoom modes or breakpoints.

Changes

  • Add updateViewportOverrides utility that injects CSS overriding viewport-height classes (h-screen, h-dvh, h-[100vh], etc.) with fixed pixel values based on a reference viewport height
  • Add measureContentExtent utility that measures actual child bounds instead of relying on scrollHeight (which inflates from h-full)
  • Wire viewport overrides into both Canvas (editor) and CenterCanvas (preview) measurement flows
  • Derive preview viewport widths from BREAKPOINTS config with a buffer to prevent CSS zoom sub-pixel rounding from toggling breakpoints
  • Measure preview content by temporarily setting body/html height to auto, with ResizeObserver disconnected to prevent feedback loops
  • Preserve current zoom mode (fit/autofit/custom) when switching viewport breakpoints instead of forcing autofit

Test plan

  • Add layers with h-screen, min-h-dvh, h-[50vh] — verify they size correctly on canvas without causing infinite height growth
  • Preview mode: switch between desktop/tablet/mobile breakpoints and verify no blank space appears at the bottom
  • Preview mode: use "Fit height" zoom, switch breakpoints, confirm zoom mode is preserved (not reset to fit-width)
  • Preview mode: "Zoom to 100%" on desktop — no extra blank space
  • Pages with large images: verify height measurement settles after images load without oscillation

- Derive viewport widths from BREAKPOINTS config to avoid sitting on
  exact breakpoint boundaries where CSS zoom rounding toggles styles
- Measure iframe content by temporarily setting body/html height to
  auto instead of resizing the wrapper (avoids viewport shifts)
- Disconnect ResizeObserver during measurement to prevent feedback
  loops from temporary style changes
- Preserve current zoom mode (fit/autofit/custom) when switching
  viewport breakpoints instead of forcing autofit
@tristan-mouchet tristan-mouchet added the Bug Something isn't working label Apr 9, 2026
@tristan-mouchet tristan-mouchet self-assigned this Apr 9, 2026
…anvas component

- Refactored the logic for determining the final iframe height to ensure it fills the canvas correctly at various zoom levels.
- Updated comments for clarity on behavior when zooming in, out, or switching viewports.
- Adjusted the className for the container to include vertical centering with `my-auto`.
@tristan-mouchet tristan-mouchet merged commit 868027c into develop Apr 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants