Fix Toolbar initialization to prevent widget serialization crash in Solara#2324
Open
Fix Toolbar initialization to prevent widget serialization crash in Solara#2324
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 <5016453+giswqs@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix geemap not working with Solara
Fix Toolbar initialization to prevent widget serialization crash in Solara
Oct 30, 2025
schwehr
reviewed
Oct 30, 2025
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 |
Collaborator
There was a problem hiding this comment.
nit: Add . at the end of sentence.
Contributor
There was a problem hiding this comment.
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.
Contributor
|
🚀 Deployed on https://69039eceea3020f992292b34--opengeos.netlify.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.