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

fix: Re-opening widgets after re-hydrated #379

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

mofojed
Copy link
Member

@mofojed mofojed commented Mar 21, 2024

  • 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
    • This was because we were calling LayoutUtils.openComponent to open the panel, which would replace the existing panel; which triggered a panel close event, then a panel open event.
    • Was also adding panel IDs multiple times to the panelIds widget data, which would cause them to re-open even if you "closed" all the panels
  • Instead, only call LayoutUtils.openComponent if the panel does not yet exist
    • If it needs a re-focus in case of metadata change (e.g. re-opening a widget), it will just set it as the active item in the stack, and update the key of the component so that it re-renders clean.
    • Add checks to ensure we're not adding panelIds multiple times, and we're removing it correctly on close
  • Added some more unit tests
  • Fixes deephaven.ui component that is persisted is not re-opened correctly #374
  • Manually tested by following the steps in the ticket

mofojed added 5 commits March 21, 2024 10:26
- 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
@mofojed mofojed requested a review from mattrunyon March 21, 2024 14:33
@mofojed mofojed self-assigned this Mar 21, 2024
plugins/ui/src/js/src/DashboardPlugin.tsx Outdated Show resolved Hide resolved
plugins/ui/src/js/src/layout/ReactPanel.test.tsx Outdated Show resolved Hide resolved
Comment on lines 51 to 52
const [widgetData] = useState<WidgetData>(() => structuredClone(data));
const [panelIds] = useState<string[]>([]);
Copy link
Collaborator

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?

Copy link
Member Author

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.

plugins/ui/src/js/src/widget/DocumentHandler.tsx Outdated Show resolved Hide resolved
plugins/ui/src/js/src/layout/ReactPanel.tsx Outdated Show resolved Hide resolved
- Extract getPreservedData method
- Add tests
- Add some more comments
@mofojed mofojed requested a review from mattrunyon March 26, 2024 18:58
Copy link
Collaborator

@mattrunyon mattrunyon left a 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

plugins/ui/src/js/src/layout/ReactPanel.tsx Outdated Show resolved Hide resolved
plugins/ui/src/js/src/widget/WidgetUtils.tsx Outdated Show resolved Hide resolved
@mofojed mofojed requested a review from mattrunyon April 3, 2024 17:42
Copy link
Collaborator

@mattrunyon mattrunyon left a 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

plugins/ui/src/js/src/layout/ReactPanel.tsx Outdated Show resolved Hide resolved
@mofojed mofojed requested a review from mattrunyon April 3, 2024 21:02
@mofojed mofojed merged commit 42242a5 into deephaven:main Apr 3, 2024
13 checks passed
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.

deephaven.ui component that is persisted is not re-opened correctly
2 participants