Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency on layout size and in-viewport #54

Open
dvoytenko opened this issue Nov 18, 2019 · 0 comments
Open

Dependency on layout size and in-viewport #54

dvoytenko opened this issue Nov 18, 2019 · 0 comments
Labels
TBD To be discussed/design decisions

Comments

@dvoytenko
Copy link
Contributor

dvoytenko commented Nov 18, 2019

For some elements their layout size is important. For instance amp-fit-text picks the right font size given its content and available layout space. In AMP layout size is provided by the framework. However, in Bento, we do not want to depend on heavy framework features and instead need to enable the components themselves to react to size changes.

We can use a relatively new ResizeObserver to monitor size changes. See useResizeObserver as an example. There are some nuances however:

  • It's near-impossible to polyfill well. ResizeObserver is available in Chrome and Firefox, and will be available in Safari very soon. That still leaves IE and Edge. Partial implementation is possible using window.onresize event, but it's a poor substitution.
  • An instance of ResizeObserver is heavy. Sharing resize observers appears to improve performance up to 8x.

Very similar reasons should guide "in-viewport" approach with IntersectionObserver.

@dvoytenko dvoytenko added the TBD To be discussed/design decisions label Nov 18, 2019
@dvoytenko dvoytenko changed the title Dependency on layout size Dependency on layout size and in-viewport Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TBD To be discussed/design decisions
Projects
None yet
Development

No branches or pull requests

1 participant