-
Notifications
You must be signed in to change notification settings - Fork 945
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
setLayout before attaching to DOM #2605
Comments
I believe it can be worth exploring, but there is a high enough chance for this to be significant that we carefully look if there are any corner cases that will break with this. |
I think we can avoid this now. Since my fix on the display logic. |
Actually if I understand correctly, this is fixed |
We might want to remove the extra code that was executed after the displayed event |
which fix are you talking about? |
Oh I'm sorry I was using the phone UI, I thought this was on the bqplot repository. You can ignore my comments :) |
After some in-person discussions on this, it seems like we could need an extra promise that would be resolved when the It would be important in bqplot because the Figure widget could look for the available space after the layout/style/CSS is applied. The bqplot 0.12.0 behavior is that the Figure is first rendered with a default size, then attached to the DOM, and only on resize event (which is triggered after attached and after the layout and style are applied) will take the available space. All of this triggers lots of rendering of the Figure and slows the whole thing down. Since this fix in bqplot: bqplot/bqplot#982, the Figure is rendered only after the In this.displayed.then(() => {
this.update_classes([], this.model.get('_dom_classes'));
this.setLayout(this.model.get('layout'));
this.setStyle(this.model.get('style'));
}); Maybe this could be set to something like: this.layoutApplied = this.displayed.then(() => {
this.update_classes([], this.model.get('_dom_classes'));
this.setLayout(this.model.get('layout'));
this.setStyle(this.model.get('style'));
}); I'm sure we can find a better name than |
What about:
|
Related to this issue. We wait for the This does not work well in the case of a tab widget. Because the |
Can ResizeObserver be relied on to resolve some ambiguity around layout events? The browser support matrix is looking pretty green now. Decreasing the dependency on Lumino DOM events may make it easier to leverage widgets in other contexts/frameworks. |
Looking at the timeline at https://caniuse.com/resizeobserver, it looks like things basically became green at the start of 2020 or so. |
Yes, eventually. In the short term, using the ResizeObserver to trigger a resize event on the root Lumino widget provides a nice transition. We could do this in the classic notebook now, for example, or in the html widget manager. |
I agree with this issue in that I think there is an optimization to be had by applying styles and layout before the widget's root node is attached to the DOM. That said, for reasons similar to that stated in #3288 (review), the |
I will do a PR to the effect of the above comment ^ |
I tried to implement the change outline above, but was unable to find a solution where the layout code runs prior to the element being attached. The main points to note are:
In sum, I wasn't able to find a way to have the I'll leave this open for now in case someone else can think of a clever solution of how to implement this, but I will move it off the 8..0 milestone. |
Currently, we wait till the DOMWidgetView object is displayed (i.e. attached to DOM), before we set the layout:
ipywidgets/packages/base/src/widget.ts
Line 810 in 92d7d42
This originally comes from this commit:
9c3de09
However, this leads to unneeded resize events. First the DOM elements get attached, and the element get a particular size, then the layout may influence the sizing, leaving several libraries (ipyvolume, bqplot, probably also ipyleaflet) to redraw itself.
I think we should set the layout, style and css _dom_classes before attaching.
The text was updated successfully, but these errors were encountered: