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

perf: clean up header routes & replace useLocation #37145

Closed
wants to merge 2 commits into from

Conversation

alex-golovanov
Copy link
Contributor

@alex-golovanov alex-golovanov commented Oct 30, 2024

Description

Reduce the amount of unnecessary renders for app header.

Fixes #37135

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11667806569
Commit: dc0b5eb
Cypress dashboard.
Tags: @tag.All
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ServerSide/QueryPane/Querypane_Mongo_Spec.js
List of identified flaky tests.
Tue, 05 Nov 2024 07:14:41 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved routing management in the app header for better clarity and maintainability.
    • Enhanced performance of the EditorTitle component through optimization techniques.
  • Bug Fixes

    • Resolved potential rendering issues in the Header component by memoizing it, preventing unnecessary updates.
  • Refactor

    • Simplified routing logic by consolidating multiple routes into fewer entries.
    • Transitioned from a hook to a function for determining application state in the Header component.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request introduces significant changes to the routing structure within the AppHeader.tsx file, replacing several constants with new arrays for better organization of paths. The routing logic is simplified by consolidating multiple Route components into fewer entries, enhancing clarity. Additionally, the EditorTitle.tsx component is optimized by using useCallback for the closeMenu function, and the Header component in index.tsx is updated to utilize identifyEntityFromPath for state management instead of a hook, while also being memoized to reduce unnecessary re-renders.

Changes

File Path Change Summary
app/client/src/ce/pages/common/AppHeader.tsx Removed constants for routing; introduced IDE_HEADER_PATHS, NAVIGATION_PATHS, PAGE_HEADER_PATHS; simplified routing logic.
app/client/src/pages/Editor/IDE/Header/EditorTitle.tsx Updated closeMenu function to use useCallback for optimization.
app/client/src/pages/Editor/IDE/Header/index.tsx Exported Header as a memoized component; replaced useCurrentAppState with identifyEntityFromPath for state management.

Assessment against linked issues

Objective Addressed Explanation
Reduce unnecessary re-renders of IDEHeader caused by route changes (#37135)

Possibly related PRs

Suggested labels

Bug

Suggested reviewers

  • albinAppsmith
  • hetunandu
  • ankitakinger

Poem

In the land of code where paths align,
The Header shines, its routes divine.
With useCallback to keep things neat,
The EditorTitle can’t be beat!
So here’s to changes that make it bright,
A clearer path, a smoother flight! ✨


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.

@github-actions github-actions bot added the Task A simple Todo label Oct 30, 2024
@alex-golovanov alex-golovanov added the ok-to-test Required label for CI label Oct 30, 2024
@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product UI Building Product Issues related to the UI Building experience UI Performance Issues related to UI performance labels Oct 30, 2024
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: 1

🧹 Outside diff range and nitpick comments (2)
app/client/src/ce/pages/common/AppHeader.tsx (1)

Line range hint 1-17: Consider optimizing imports

The route constants could be destructured directly in the path array declarations to reduce the number of unused variables in the module scope.

import {
-  VIEWER_PATH,
-  BUILDER_PATH,
-  BUILDER_PATH_DEPRECATED,
-  VIEWER_PATH_DEPRECATED,
-  ADMIN_SETTINGS_CATEGORY_PATH,
-  VIEWER_CUSTOM_PATH,
-  BUILDER_CUSTOM_PATH,
-  BASE_URL,
+  BUILDER_PATH_DEPRECATED, BUILDER_PATH, BUILDER_CUSTOM_PATH,
+  VIEWER_PATH_DEPRECATED, VIEWER_PATH, VIEWER_CUSTOM_PATH,
+  ADMIN_SETTINGS_CATEGORY_PATH, BASE_URL,
} from "constants/routes";
app/client/src/pages/Editor/IDE/Header/index.tsx (1)

Line range hint 93-120: Consider memoizing HeaderTitleComponent for additional render optimization.

While the current implementation is correct, memoizing this component could further reduce unnecessary re-renders when parent components update.

-const HeaderTitleComponent = ({ appState, currentPage }: HeaderTitleProps) => {
+const HeaderTitleComponent = React.memo(({ appState, currentPage }: HeaderTitleProps) => {
   const libraryHeaderTitle = useLibraryHeaderTitle();
 
   switch (appState) {
     case EditorState.DATA:
       return (
         <IDEHeaderTitle
           key={appState}
           title={createMessage(HEADER_TITLES.DATA)}
         />
       );
     case EditorState.EDITOR:
       return <EditorTitle key={appState} title={currentPage?.pageName || ""} />;
     case EditorState.SETTINGS:
       return (
         <IDEHeaderTitle
           key={appState}
           title={createMessage(HEADER_TITLES.SETTINGS)}
         />
       );
     case EditorState.LIBRARIES:
       return <IDEHeaderTitle key={appState} title={libraryHeaderTitle} />;
     default:
       return <EditorTitle key={appState} title={currentPage?.pageName || ""} />;
   }
-};
+});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ff70e3a and f8323b7.

📒 Files selected for processing (4)
  • app/client/src/ce/pages/common/AppHeader.tsx (1 hunks)
  • app/client/src/ee/pages/common/AppHeader.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/Header/EditorTitle.tsx (2 hunks)
  • app/client/src/pages/Editor/IDE/Header/index.tsx (2 hunks)
🔇 Additional comments (7)
app/client/src/ee/pages/common/AppHeader.tsx (2)

1-4: Clean refactoring that improves performance!

The simplification from a class-based component to direct route exports aligns well with the goal of reducing unnecessary renders.


1-2: Verify CE routes coverage for EE features

Let's ensure the CE routes implementation handles all enterprise-specific routes.

✅ Verification successful

Let me check the EE-specific route implementations to ensure complete coverage.


Let me try a different approach to verify the routes.


CE routes implementation is sufficient for EE features

The EE AppHeader is a direct re-export of CE AppHeader with no additional routes or modifications. The CE implementation already covers all necessary routing paths including IDE, navigation, and page header routes. No EE-specific routes need to be handled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any EE-specific routes that might need handling

# Look for route definitions in EE-specific components
rg -l "Route|useNavigate|useLocation" "app/client/src/ee"

# Compare with CE routes implementation
ast-grep --pattern 'const $_ = [$$$]' "app/client/src/ce/pages/common/AppHeader.tsx"

Length of output: 1229


Script:

#!/bin/bash
# Check EE-specific route definitions and compare with CE
rg -A 5 "export const.*Routes" app/client/src/ee/constants/routes/appRoutes.ts

# Check if there are any EE-specific route usages
rg "useNavigate|useLocation" app/client/src/ee/pages/common/AppHeader.tsx

# Look for any route-related constants or paths in EE AppHeader
ast-grep --pattern 'const $_ = [$$$]' app/client/src/ee/pages/common/AppHeader.tsx

Length of output: 241


Script:

#!/bin/bash
# Check the actual content of both CE and EE AppHeader files
cat app/client/src/ce/pages/common/AppHeader.tsx
echo "---EE AppHeader---"
cat app/client/src/ee/pages/common/AppHeader.tsx

# Look for any route-related imports or re-exports
rg -A 3 "import.*Route|export.*Route" app/client/src/ee/pages/common/AppHeader.tsx

Length of output: 1443

app/client/src/pages/Editor/IDE/Header/EditorTitle.tsx (1)

11-13: LGTM: Effective use of useCallback for render optimization.

The memoization of closeMenu function aligns well with the PR's performance optimization goals.

app/client/src/ce/pages/common/AppHeader.tsx (2)

18-30: Well-structured path organization

The grouping of related paths into separate constants improves code organization and should help reduce unnecessary re-renders by consolidating route checks.


32-46: Clean route implementation, verify matching behavior

The consolidated routing approach looks good and aligns with the goal of reducing re-renders. However, let's verify that the route matching behaves correctly for all paths.

app/client/src/pages/Editor/IDE/Header/index.tsx (2)

80-80: LGTM: Import change aligns with performance objectives.

The addition of identifyEntityFromPath supports the transition from hook-based state management to a more efficient path-based approach.


158-158: Verify the path-based state determination impact.

The change from useCurrentAppState hook to identifyEntityFromPath should reduce unnecessary re-renders. However, let's verify all possible path patterns are handled correctly.

✅ Verification successful

Let me gather more information about the identifyEntityFromPath implementation since it wasn't found in the previous search.


Let me check the implementation of matchEntityFromPath since it's used within identifyEntityFromPath.


Let me check the implementation of getMatchPaths and getIDETypeByUrl to understand the path matching logic.


Let me check the EntityPaths and IDEBasePaths to complete the verification of path patterns.


Path-based state determination is correctly implemented

The change from useCurrentAppState hook to direct identifyEntityFromPath is safe. The implementation:

  • Handles all IDE paths (editor, data, settings, libraries) via EntityPaths
  • Supports both new and deprecated URL patterns through IDEBasePaths
  • Maintains consistent state mapping across the application
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all possible path patterns that could affect appState determination

# Test: Search for route definitions and path patterns
rg -g '*.{ts,tsx}' -A 3 'EditorState\.' 

# Test: Search for identifyEntityFromPath usage to ensure consistent implementation
ast-grep --pattern 'identifyEntityFromPath($path)'

Length of output: 26686


Script:

#!/bin/bash
# Search for identifyEntityFromPath implementation
rg -g '*.{ts,tsx}' -A 10 'function identifyEntityFromPath|const identifyEntityFromPath'

# Search for any imports of identifyEntityFromPath
rg -g '*.{ts,tsx}' 'import.*identifyEntityFromPath'

Length of output: 3526


Script:

#!/bin/bash
# Search for matchEntityFromPath implementation and its path patterns
rg -g '*.{ts,tsx}' -A 15 'function matchEntityFromPath|const matchEntityFromPath'

# Search for route patterns that might be used in matching
rg -g '*.{ts,tsx}' 'path:.*editor' -A 2

Length of output: 1161


Script:

#!/bin/bash
# Search for getMatchPaths and getIDETypeByUrl implementations
rg -g '*.{ts,tsx}' -A 10 'function getMatchPaths|const getMatchPaths|function getIDETypeByUrl|const getIDETypeByUrl'

# Search for IDE route patterns
rg -g '*.{ts,tsx}' 'const IDE_PATH|const BUILDER_PATH|const VIEWER_PATH' -A 3

Length of output: 3253


Script:

#!/bin/bash
# Search for EntityPaths and IDEBasePaths definitions
rg -g '*.{ts,tsx}' -A 5 'const EntityPaths|const IDEBasePaths'

# Search for any route path constants that might be used in these paths
rg -g '*.{ts,tsx}' 'const.*PATH.*=.*/(datasource|queries|api|jsObjects|settings|libraries)' -A 1

Length of output: 3880

@alex-golovanov alex-golovanov added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Oct 31, 2024
@alex-golovanov alex-golovanov added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 4, 2024
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 12, 2024
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI Stale Task A simple Todo UI Building Product Issues related to the UI Building experience UI Performance Issues related to UI performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce unnecessary re-renders of IDEHeader caused by route changes
1 participant