-
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
Error with 8.0.5 when selecting ipytree node #3735
Error with 8.0.5 when selecting ipytree node #3735
Comments
@manzt didn't expect to see this! Which browser is this? |
cc @martinRenou |
Interesting. This is certainly related to replacing EDIT:
To illustrate: let p = Promise.resolve("foo");
JSON.parse(JSON.stringify([p, 10])); // [{}, 10]
structuredClone([p, 10]); // Uncaught DOMException: Failed to execute 'structuredClone' on 'Window': #<Promise> could not be cloned.
|
I think you should be able to fix this in ipytree by implementing a ipywidgets/packages/base/src/widget.ts Lines 526 to 548 in 93a848b
TreeModel.serializers = {
...widgets.DOMWidgetModel.serializers,
nodes: { deserialize: widgets.unpack_models },
selected_nodes: { deserialize: widgets.unpack_models }
}; I think this might actually be a bug with the implementation of I believe the correct serializer implementation would be: TreeModel.serializers = {
...widgets.DOMWidgetModel.serializers,
nodes: { deserialize: widgets.unpack_models },
selected_nodes: {
deserialize: widgets.unpack_models,
serialize(nodes) {
return nodes.map(model => `IPY_MODEL_${model.model_id}`);
}
}
}; |
Done
Yup, my (long-winded) explanation above was just pointing to the fact that folks might be relying on unexpected behavior in the prior default serializer ( |
Making every downstream package update on a point release because "our old implementation was suspect," seems like... an unfriendly move. Can we restore the appearance of the old behavior, and get the new benefits? Basically, if |
I think it is extremely unlikely that every downstream package will need an update due to this change (elaborated below), but I certainly see your point. Perhaps just make the new default cloning re-coverable, wrapping in a To be clear, it's completely fine to only implement |
Counterpoint: any library (or user) use of from ipywidgets import *
slider = FloatSlider()
box1 = HBox([slider])
box2 = VBox([])
jslink((box1, "children"), (box2, "children")) |
A quick fix may be to set proper serializers on the the boxes children? |
quick fixes are what got us here, let's do it right, and test a bunch of downstreams with the behavior in e.g. binder.
If it's good enough for the goose... again, i think if |
Here's a strawman PR: might not be able to bring it home, but do intend to check on binder/lite... |
Thanks for the PR! Looking into this deeper, I think JSON.stringify([ { toJSON: () => "FOO" }, { bar: { toJSON: () => "BAR" }, answer: 42 }])
// '["FOO",{"bar":"BAR","answer":42}]' so, JSON.stringify([model1, model2])
// '[ "IPY_MODEL_<model_id>", "IPY_MODEL_<model_id>"]' I was not aware of this behavior previously, and think your check for |
The assumption of |
Note that this also broke pythreejs, as it uses its own deserializer like this: Since the fix in #3738 checks equality directly against |
The following is broken since #3689:
As a result, I also would be in favor of reverting the PR in a patch release of ipywidgets. Does that sound good to everyone? Also pinging @ibdafna @mwcraig for opinions |
With the caveat that my understanding of the underlying issue is limited to what I've read here and in the PR #3689, yes, I'm in favor of reverting the change until we can provide a graceful fallback of some sort. |
(the reverts seems to have fixed this for pythreejs, I assume for ipytree as well?) |
Yes, they should have. |
Description
I have an ipytree widget in Jupyterlab, and on clicking a node of it getting errors:
Error serializing widget state attribute: selected_nodes
serialize @ 595.7f2125f3d2c7376588c2.js?v=7f2125f3d2c7376588c2:1
sync @ 595.7f2125f3d2c7376588c2.js?v=7f2125f3d2c7376588c2:1
save @ 644.7d1bff49f8e38fac4070.js?v=7d1bff49f8e38fac4070:1
save_changes @ 595.7f2125f3d2c7376588c2.js?v=7f2125f3d2c7376588c2:1
(anonymous) @ 568.c44c0ae4f70f7df0fe86.js?v=c44c0ae4f70f7df0fe86:1
dispatch @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
v.handle @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
trigger @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
triggerHandler @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
trigger @ 287.fd063a1253f3266560f7.js?v=fd063a1253f3266560f7:2
select_node @ 287.fd063a1253f3266560f7.js?v=fd063a1253f3266560f7:2
activate_node @ 287.fd063a1253f3266560f7.js?v=fd063a1253f3266560f7:2
(anonymous) @ 287.fd063a1253f3266560f7.js?v=fd063a1253f3266560f7:2
dispatch @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
v.handle @ 755.71bcc770291b01d6ebaa.js?v=71bcc770291b01d6ebaa:2
Uncaught DOMException: Failed to execute 'structuredClone' on 'Window': # could not be cloned.
Reproduce
In Jupyterlab (3.4.5):
from ipytree import Node, Tree
tree = Tree()
subtree = Node()
tree.add_node(subtree)
subtree.add_node(Node())
tree
Expected behavior
Context
When downgrading to ipywidgets==8.0.4 and jupyterlab_widgets==3.0.5 versions the widget works as expected without errors.
Troubleshoot Output
Command Line Output
Browser Output
If using JupyterLab
Installed Labextensions
The text was updated successfully, but these errors were encountered: