-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Toolbar initialization to prevent widget serialization crash in Solara #2324
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
base: master
Are you sure you want to change the base?
Conversation
Use hold_trait_notifications() context manager to batch trait updates during Toolbar.__init__() to prevent premature widget serialization that causes errors in Solara environment. Co-authored-by: giswqs <[email protected]>
geemap/toolbar.py
Outdated
| self.main_tools = main_tools + ([self.toggle_widget] if extra_tools else []) | ||
| self.extra_tools = extra_tools | ||
| # Use hold_trait_notifications to avoid triggering widget serialization | ||
| # during initialization, which can cause issues in Solara and other environments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add . at the end of sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses widget serialization issues during toolbar initialization in environments like Solara. The change wraps the assignment of main_tools and extra_tools attributes within a hold_trait_notifications() context manager to prevent premature trait notifications that could trigger serialization problems.
- Wraps
main_toolsandextra_toolsassignment inhold_trait_notifications()context - Adds explanatory comment about the serialization issue prevention
- Maintains existing initialization logic while deferring trait notifications
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🚀 Deployed on https://69039eceea3020f992292b34--opengeos.netlify.app |
geemap crashes when used with Solara due to premature widget serialization during Toolbar initialization. Setting
main_toolsandextra_toolstraits (which havesync=Truewithwidget_serialization) triggers immediate serialization before initialization completes, causing the error in ipywidgets'_widget_to_json.Changes
Wrapped trait assignments in
hold_trait_notifications()context manager inToolbar.__init__():This follows the traitlets recommended pattern for multiple trait assignments during initialization, ensuring all widgets are in a consistent state before serialization occurs.
Original prompt
This section details on the original issue you should resolve
<issue_title>geemap not working with Solara</issue_title>
<issue_description>Web App: https://huggingface.co/spaces/giswqs/solara-geemap
How to reproduce it:
git clone https://huggingface.co/spaces/giswqs/solara-geemap
pip install -r requirements.txt
solara run ./pages/
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.