Skip to content

Observe resize of slide contents in experimental slide-content-overflow diagnostic #526

@yhatt

Description

@yhatt

Related: #519

Problems

Currently slide-content-overflow diagnostic detects the size of slide contents only when Markdown preview was updated by editting. However, it may not apply diagnostic correctly in following cases:

  • Remote images: The size of image elements is not known until they are fully loaded.
  • CSS animations: If the slide is including CSS animations, the size of slide content may change during the animation.

Limitations

For following reasons, we are not using ResizeObserver for now (v3.3.0):

  • ResizeObserver cannot detect changing the size of inner contents.
  • If the wrapper element were injected to each slide page for making ResizeObserver work, CSS styling by Marp theme and inline styles may break.

Solutions

To observe resize slide contents in each page, we might take either one:

  • Mix MutationObserver with ResizeObserver: MutationObserver observes subtree changes, and ResizeObserver observes all of children for each page detected by MutationObserver.
  • Polling: Regularly check the size of slide contents.

scrollHeight and scrollWidth to get the size of contents in a page will force reflow and bring performance degradation, so we have to minimize frequency to check the overflow.
https://gist.github.com/paulirish/5d52fb081b3570c81e3a

So I think it's better to trigger the throttled overflow detection by MutationObserver + ResizeObserver.
https://developer.mozilla.org/en-US/docs/Glossary/Throttle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions