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(auth): prevent infinite redirect #10065

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

AMoreaux
Copy link
Contributor

@AMoreaux AMoreaux commented Feb 6, 2025

Refactored the isMatchingLocation function to use useCallback for memoization, improving performance by avoiding unnecessary re-creations. Moved addTrailingSlash and getConstructedPath inside useCallback for better encapsulation.

Refactored the isMatchingLocation function to use useCallback for memoization, improving performance by avoiding unnecessary re-creations. Moved addTrailingSlash and getConstructedPath inside useCallback for better encapsulation.
@AMoreaux AMoreaux self-assigned this Feb 6, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR optimizes the useIsMatchingLocation hook by implementing memoization to prevent unnecessary re-renders during route matching operations.

  • Refactored useIsMatchingLocation in /packages/twenty-front/src/hooks/useIsMatchingLocation.ts to use useCallback for performance optimization
  • Moved helper functions addTrailingSlash and getConstructedPath inside useCallback for better encapsulation
  • Simplified return statement by removing intermediate variable, maintaining same functionality
  • Correctly specified location.pathname as the only dependency in useCallback

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +13 to +14
const addTrailingSlash = (path: string) =>
path.endsWith('/') ? path : path + '/';
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Moving these helper functions inside useCallback creates new function instances on every call. Consider moving them outside the callback or memoizing them separately if they're used elsewhere.

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.

1 participant