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

Fixes an issue where splitting the panel space wrongly triggers on_unload #5296

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

manivoxel51
Copy link
Contributor

@manivoxel51 manivoxel51 commented Dec 18, 2024

What changes are proposed in this pull request?

  • Testing DQ panel shows when splitting the panel's space using [][], the on_unload hook is called
  • moving the on_unload trigger to PanelCloseEffect function fixes the issue
Screen.Recording.2024-12-18.at.1.10.42.PM.mov

How is this patch tested? If it is not, please explain why.

(Details)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced event handling in the Custom Panel for unload actions.
  • Bug Fixes

    • Removed cleanup effect for the onUnLoad prop, streamlining lifecycle interactions.
  • Refactor

    • Updated state management logic for the Custom Panel.
    • Introduced conditional checks for event triggers based on schema changes.

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces changes to the CustomPanel and useCustomPanelHooks modules, focusing on enhancing event handling capabilities. In CustomPanel.tsx, a new usePanelEvent hook is imported and integrated to trigger panel unload events. The defineCustomPanel function now includes an on_unload parameter. In useCustomPanelHooks.ts, the cleanup effect for onUnLoad is removed, and new functions are added to manage panel state changes with improved conditional logic and debounce mechanisms.

Changes

File Change Summary
app/packages/operators/src/CustomPanel.tsx - Added import for usePanelEvent
- Introduced triggerPanelEvent in CustomPanel function
- Updated defineCustomPanel to include on_unload parameter
app/packages/operators/src/useCustomPanelHooks.ts - Removed cleanup effect for onUnLoad
- Added handlePanelStateChange function
- Modified handlePanelStatePathChange with conditional event triggering
- Created debounced versions of state handling functions

Sequence Diagram

sequenceDiagram
    participant CustomPanel
    participant usePanelEvent
    participant PanelHooks

    CustomPanel->>usePanelEvent: Initialize triggerPanelEvent
    CustomPanel->>PanelHooks: Call onUnLoad
    PanelHooks-->>CustomPanel: Handle panel state changes
    CustomPanel->>usePanelEvent: Trigger panel unload event
Loading

Possibly related PRs

Suggested labels

enhancement, app

Suggested reviewers

  • ritch
  • imanjra

Poem

🐰 Panels dancing, events in flight,
Code refactored with rabbit's might!
Hooks and triggers, smooth and clean,
A custom panel's new routine
Hopping through state with pure delight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/packages/operators/src/CustomPanel.tsx (1)

40-42: Consider adding documentation for the unload behavior

While the implementation is correct, it would be beneficial to add a comment explaining why the on_unload trigger needs to be in the panel close effect specifically, to prevent future regressions.

    setPanelCloseEffect(() => {
      clearUseKeyStores(panelId);
      trackEvent("close_panel", { panel: panelName });
+     // Trigger on_unload only during actual panel closure to prevent incorrect triggers during panel splits
      triggerPanelEvent(panelId, { operator: props.onUnLoad });
    });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff0c2e7 and cf3d4a2.

📒 Files selected for processing (2)
  • app/packages/operators/src/CustomPanel.tsx (2 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • app/packages/operators/src/useCustomPanelHooks.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/operators/src/CustomPanel.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (4)
app/packages/operators/src/CustomPanel.tsx (4)

17-17: LGTM: Clean import of the new hook

The import follows React hook naming conventions and is properly organized with other hook imports.


24-24: LGTM: Proper hook initialization

The hook is correctly initialized at the component's top level, following React hooks rules.


Line range hint 115-166: LGTM: Consistent parameter and prop handling

The on_unload parameter is properly integrated into the function signature and correctly passed as onUnLoad prop, maintaining consistency with React naming conventions.


40-42: Verify the unload event triggering sequence

The change fixes the incorrect on_unload triggering by moving it to the panel close effect. However, we should verify that this doesn't introduce any race conditions with the store clearing operation.

✅ Verification successful

No race conditions found in panel unload sequence

The code analysis shows that clearUseKeyStores is properly synchronized with the panel close effect. The sequence is:

  1. clearUseKeyStores is called first to clean up the stores
  2. trackEvent is called to log the panel closure
  3. triggerPanelEvent with onUnLoad is called last

This order ensures that store cleanup happens before any unload handlers are triggered, preventing potential race conditions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other potential race conditions in panel unload handling
ast-grep --pattern 'useEffect(() => {
  $$$
  clearUseKeyStores($_)
  $$$
})'

Length of output: 79


Script:

#!/bin/bash
# Search for clearUseKeyStores usage and its surrounding context
rg "clearUseKeyStores" -A 5 -B 5

# Search for panel unload related effects
ast-grep --pattern 'useEffect(() => {
  $$$
  onUnload($$$)
  $$$
})'

# Search for panel close related code
rg "close_panel|onUnload|triggerPanelEvent" -A 3 -B 3

Length of output: 18791

@manivoxel51 manivoxel51 changed the title Fixes an issue where spliting the panel space wrongly triggers on_unload Fixes an issue where splitting the panel space wrongly triggers on_unload Dec 18, 2024
Copy link
Contributor

@jleven jleven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this change affects all custom panels, is that right? Am I right to assume there are several of those?

If so, I'd be very curious to know how you've tested that this doesn't cause any regressions in existing panels.

@manivoxel51
Copy link
Contributor Author

So this change affects all custom panels, is that right? Am I right to assume there are several of those?

If so, I'd be very curious to know how you've tested that this doesn't cause any regressions in existing panels.

I searched for on_unload in teams and oss but didn't find much reference - DQ panel is the only one implementing that from the recent CustomPanels.

also made sure all built-in panels (DQ, QP, Lens, etc) can be opened and closed properly after the change.

@imanjra @Br2850 if there are other areas I am missing to test lmk.

Copy link
Contributor

@Br2850 Br2850 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 great catch, should fix a lot of other downstream double calling in customer panel's

Copy link
Contributor

@imanjra imanjra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@manivoxel51 manivoxel51 merged commit 613913f into develop Dec 19, 2024
12 checks passed
@manivoxel51 manivoxel51 deleted the bug/split-unload branch December 19, 2024 20:33
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
7 tasks
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.

4 participants