-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: Re-opening widgets after re-hydrated #379
Conversation
- There was a race condition when replacing the widget, where the old panel content was getting removed before the new panel was being put up - In that case, we want to wait for the portal opened event before emitting an open event - Also check that we're not getting a duplicate open event in the panel manager - The duplicate panel ID was getting logged with the widget that was saved, which would sometimes cause widgets to randomly re-open - Still screwing up in some cases. Panel manager is getting the open event twice and therefore not keeping track of the IDs correctly
- Need to update unit tests - Tested with two widgets, `foo` and `bar` - Tested that they saved with the layout when opened - Tested that they re-activated when re-creating the item in the console (re-opening it) - Tested that they were removed from the plugin data when all panels closed - TODO: Handling if there's errors loading the widget on startup, showing a loading spinner in panels while loading the widget
- Basically reverted to what they were before, which is good
const [widgetData] = useState<WidgetData>(() => structuredClone(data)); | ||
const [panelIds] = useState<string[]>([]); |
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.
Why useState
with no setter instead of useRef
? Also, why is panelIds
separate from widgetData.panelIds
here?
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 a comment about why I did it specifically for widgetData
.
For panelIds
, I could use useRef
. Just means I'd be adding .current
everywhere else.
- Extract getPreservedData method - Add tests - Add some more comments
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.
Just a few small things. I also need to pull and test this still to see if I can break it
Co-authored-by: Matthew Runyon <[email protected]>
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.
Looks good. Only issue I found is just a bug and not a regression, so can be fixed separately
Just the one minor thing
LayoutUtils.openComponent
to open the panel, which would replace the existing panel; which triggered a panel close event, then a panel open event.panelIds
widget data, which would cause them to re-open even if you "closed" all the panelsLayoutUtils.openComponent
if the panel does not yet existpanelIds
multiple times, and we're removing it correctly on close