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

Experiment with ways a frontend can support ipywidgets 7 and 8 #3524

Closed
wants to merge 4 commits into from

Conversation

jasongrout
Copy link
Member

@jasongrout jasongrout commented Jul 16, 2022

This is an experiment in distributing a plain HTMLManager AMD module in the dist directory, and makes the manager more flexible in that even the core controls can be overridden. The idea here is that HTMLManager can be used and even the core controls overridden (for example, possibly the widgets 7 version of core controls could be used?)

This is partly an attempt to address #3429, and maybe providing a way to load either widgets 7 or widgets 8 controls depending on what was requested by the kernel at runtime.

@jasongrout jasongrout added this to the 8.0 milestone Jul 16, 2022
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch jasongrout/ipywidgets/amd8

@jasongrout jasongrout force-pushed the amd8 branch 2 times, most recently from 2e60e0b to 219d003 Compare July 16, 2022 14:16
This allows the HTML manager to instead load, for example, older versions of the core controls. The idea is that the HTML Manager can load either the ipywidgets 7 or ipywidgets 8 version of core controls, to support either during a transition time.

It also allows the HTML manager to be used without loading all of the base controls, if desired, making it strictly more flexible.
This could be used to determine what widgets we can invoke from the frontend. We can also use this to query what version of the base widget is registered, which gives clues about what version of ipywidgets is installed.

To determine what version of ipywidgets is installed, this is a rather indirect route, so it's not so satisfactory for that purpose.
@jasongrout
Copy link
Member Author

I also experimented with adding a new control comm message, like suggested in #3429 (comment)

@jasongrout jasongrout changed the title Distribute plain html manager AMD module Experiment with ways a frontend can support ipywidgets 7 and 8 Jul 16, 2022
@jasongrout
Copy link
Member Author

jasongrout commented Jul 17, 2022

New idea that seems much simpler:

Make @jupyter-widgets/controls from ipywidgets 7.x work with ipywidgets 8, and @jupyter-widgets/controls from ipywidgets 8 work with ipywidgets 7. Create dist/ folders in the published @jupyter-widgets/controls packages for both that contain single anonymous amd modules. Then modify html manager to pull the core controls from CDN if the version number does not match what was bundled with the html manager (in core controls for widgets 7.x and for 8.0). We might still have an issue with CSS from the bundled controls stomping on the CSS from what is being pulled from CDN, but let's see what it looks like first. Perhaps we don't load the built-in controls first, and only load those dynamically as needed, so if we are dealing with a widgets 7 system, we never end up loading the widgets 8 controls.

@jasongrout
Copy link
Member Author

We might still have an issue with CSS from the bundled controls stomping on the CSS from what is being pulled from CDN

To take care of this, we can assume that either controls for 7.x or controls for 8.x will be loaded, but not both. Then we can dynamically load either controls versions as needed (with the css for that version).

@jasongrout jasongrout marked this pull request as ready for review July 26, 2022 16:54
@jasongrout jasongrout marked this pull request as draft July 26, 2022 16:54
@jasongrout
Copy link
Member Author

In the widgets dev meeting, we decided to conclude these experiments for now. To summarize lessons:

  1. The widget control message could work, but is kind of abusing the widget registration system. The widget registration system is for kernel-side widgets to register themselves to be instantiated from the browser, but here we are using that information to assume what widgets will be instantiated in the browser from the kernel (i.e., the other way around). In practice, the assumption that these are the same probably holds, but it still has a code smell. An advantage of this approach is that we can preemptively decide whether to instantiate a widgets 7 or widgets 8 widget manager, before we get any actual widgets created, so we have very clean separate codepaths for supporting ipywidgets 7 and ipywidgets 8.
  2. The "load core widgets 7 and widgets 8" and use whatever the kernel wants should work in js (i.e., the core controls for 7 should work with the 8 widget manager), but there are still concerns around the css from one messing with the css from the other. These could be alleviated with a new 7.8 and 8.1 release that completely separated the css.

In the end, we're still not sure how much of an issue it will be for frontends in practice, so I hesitate to spend more time and effort in exploring this. If it becomes a problem in practice after we release, we have several avenues to mitigate issues.

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

Successfully merging this pull request may close these issues.

1 participant