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

Use ResizeObserver to trigger resize events in html manager and classic notebook #3282

Open
jasongrout opened this issue Sep 17, 2021 · 2 comments
Milestone

Comments

@jasongrout
Copy link
Member

In #3124, @ibdafna listened for window resize events as a proxy for if a root widget view needed to have a resize event triggered. This is a coarse proxy, since changing a browsers window size may or may not mean that the root widget size changed, and something else on the page may also change the root widget size and we wouldn't know if the browser window size didn't change.

@blois pointed out in #2605 (comment) that the standardized ResizeObserver is now pretty well supported (at least since early 2020).

That means that we can now use a ResizeObserver on each root widget DOM element instead of listening to the window resize event to give more precise triggering of this event. I'd suggest checking for the existence of ResizeObserver, and falling back to the window resize event if it doesn't exist.

The relevant code to change from #3124 is https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/src/htmlmanager.ts#L38-L45 and https://github.com/jupyter-widgets/ipywidgets/blob/master/widgetsnbextension/src/extension.js#L78-L85

@jasongrout
Copy link
Member Author

That means that we can now use a ResizeObserver on each root widget DOM element

Actually, WICG/resize-observer#59 suggests having a single resize observer observing all root widget DOM elements would be much better.

@maartenbreddels
Copy link
Member

@mariobuikhuizen implemented this for bqplot in bqplot/bqplot#1531

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants