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

refactor: optimisations #3523

Merged
merged 34 commits into from
Nov 4, 2024
Merged

refactor: optimisations #3523

merged 34 commits into from
Nov 4, 2024

Conversation

wingkwong
Copy link
Member

@wingkwong wingkwong commented Jul 21, 2024

📝 Description

(1) replace lodash with native approaches

  • replaced most lodash usages with native approaches.

(2) framer motion

Affected components:

  • accordion
  • calendar
  • modal
  • navbar
  • popover
  • ripple
  • tooltip

Unchanged components:

  • tabs

For tabs component, we need to use domMax to achieve the shifting when switching between tabs. We cannot use dynamic load here as it fails sometimes, e.g. the animation will be gone sometimes. probably a bug in framer-motion.

⛳️ Current behavior (updates)

vite-template + 8 above-mentioned components

dist/index.html                     0.97 kB │ gzip:   0.46 kB
dist/assets/favicon-DI5FVxIz.ico   15.09 kB
dist/assets/index-DhrH5Nzw.css    215.57 kB │ gzip:  23.66 kB
dist/assets/index-32UuhZvQ.js     916.79 kB │ gzip: 292.41 kB

🚀 New behavior

vite-template + 8 above-mentioned components

dist/index.html                     0.97 kB │ gzip:   0.46 kB
dist/assets/favicon-DI5FVxIz.ico   15.09 kB
dist/assets/index-DhrH5Nzw.css    215.57 kB │ gzip:  23.66 kB
dist/assets/index-CAu8Gkyy.js      57.71 kB │ gzip:  20.37 kB
dist/assets/index-C3R4YDRP.js     855.12 kB │ gzip: 269.47 kB
  • left: before, right: after (initial load time has been reduced)
  • /doc includes the above-mentioned 8 components that use LazyMotion.

image

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced several new utility functions: debounce, uniqBy, omit, kebabCase, mapKeys, get, and intersectionBy to enhance functionality.
    • Added a new package @nextui-org/dom-animation for improved DOM animations.
  • Bug Fixes

    • Updated the testGoodContrast function for better clarity and maintainability in color testing.
    • Streamlined import statements and removed dependencies on lodash, enhancing performance and code clarity.
  • Chores

    • Updated various package.json files to reflect dependency changes, including upgrading framer-motion to version 11.9.0.

Copy link

vercel bot commented Jul 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 8:44pm
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 8:44pm

Copy link

changeset-bot bot commented Jul 21, 2024

🦋 Changeset detected

Latest commit: b86e5a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 54 packages
Name Type
@nextui-org/calendar Patch
@nextui-org/theme Patch
@nextui-org/use-infinite-scroll Patch
@nextui-org/shared-utils Patch
@nextui-org/accordion Patch
@nextui-org/modal Patch
@nextui-org/navbar Patch
@nextui-org/popover Patch
@nextui-org/ripple Patch
@nextui-org/tooltip Patch
@nextui-org/dom-animation Patch
@nextui-org/autocomplete Patch
@nextui-org/button Patch
@nextui-org/card Patch
@nextui-org/dropdown Patch
@nextui-org/select Patch
@nextui-org/snippet Patch
@nextui-org/tabs Patch
@nextui-org/system Patch
@nextui-org/framer-utils Patch
@nextui-org/date-picker Patch
@nextui-org/react Patch
@nextui-org/alert Patch
@nextui-org/avatar Patch
@nextui-org/badge Patch
@nextui-org/breadcrumbs Patch
@nextui-org/checkbox Patch
@nextui-org/chip Patch
@nextui-org/code Patch
@nextui-org/date-input Patch
@nextui-org/divider Patch
@nextui-org/drawer Patch
@nextui-org/image Patch
@nextui-org/input Patch
@nextui-org/kbd Patch
@nextui-org/link Patch
@nextui-org/listbox Patch
@nextui-org/menu Patch
@nextui-org/pagination Patch
@nextui-org/progress Patch
@nextui-org/radio Patch
@nextui-org/scroll-shadow Patch
@nextui-org/skeleton Patch
@nextui-org/slider Patch
@nextui-org/spacer Patch
@nextui-org/spinner Patch
@nextui-org/switch Patch
@nextui-org/table Patch
@nextui-org/user Patch
@nextui-org/use-data-scroll-overflow Patch
@nextui-org/use-pagination Patch
@nextui-org/aria-utils Patch
@nextui-org/react-utils Patch
@nextui-org/use-real-shape Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wingkwong wingkwong added this to the v2.5.0 milestone Jul 21, 2024
Copy link
Contributor

coderabbitai bot commented Jul 21, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve the introduction of several new utility functions in the shared-utils package, including debounce, uniqBy, omit, kebabCase, mapKeys, and get. The capitalize function has been updated for input validation. Additionally, the testGoodContrast function in the semantic-colors.test.ts file has been modified to accept color values directly. Multiple components have updated their framer-motion dependency versions, and import statements have been adjusted to utilize shared utilities instead of external libraries.

Changes

File(s) Change Summary
packages/core/theme/tests/semantic-colors.test.ts Updated testGoodContrast function to accept color and background parameters directly.
packages/utilities/shared-utils/src/functions.ts Updated capitalize function and added new utility functions: debounce, uniqBy, omit, kebabCase, mapKeys, and get.
apps/docs/components/sandpack/use-sandpack.ts Updated framer-motion dependency version from "11.0.22" to "11.9.0".
Multiple package.json files across components Updated framer-motion version in peerDependencies and dependencies to >=11.5.6 and ^11.9.0 respectively; added @nextui-org/dom-animation in relevant files.

Assessment against linked issues

Objective Addressed Explanation
Ensure text is sharp when modal opens (related to blurry text issue) The changes do not address the specific issue of blurry text in modals.
Prevent blurry animations during size transitions (related to button blur issue) The changes may indirectly impact animations, but it is unclear if they resolve the blur issue.

Possibly related PRs

Suggested labels

👀 Status: In Review, 📋 Scope : Docs

Suggested reviewers

  • wingkwong

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.

@wingkwong wingkwong marked this pull request as draft September 30, 2024 17:20
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

🧹 Outside diff range and nitpick comments (2)
packages/components/modal/src/modal-transition.ts (2)

29-29: Approved with suggestion: Consider consistency in willChange usage

The addition of willChange: "transform" to the exit state is a good optimization, specifically targeting the transform property which is the main focus of the exit animation. This should help with performance during the modal's closing transition.

However, for consistency with the enter state and to account for the opacity animation, you might consider using willChange: "auto" here as well. This would allow the browser to optimize for all changing properties, including both transform and opacity.

Consider changing to:

- willChange: "transform",
+ willChange: "auto",

This maintains consistency with the enter state and covers all animated properties.


Line range hint 1-36: Overall: Effective optimization addressing the blurry text issue

These changes to the scaleInOut transition object represent a targeted approach to resolving the blurry text issue reported in #3817. By adding willChange properties to both the enter and exit states, you're providing valuable hints to the browser for optimizing the modal's rendering and animation performance.

The use of willChange: "auto" for the enter state and willChange: "transform" for the exit state should effectively address the Chrome rendering issue with CSS transforms and percentage-based values. This solution is likely to result in sharper text rendering when the modal is opened, improving the overall user experience without requiring additional actions like window resizing.

While there's a slight inconsistency in the willChange values between enter and exit states, both approaches are valid and should yield performance improvements. Great job on implementing these optimizations!

To further improve this component, consider:

  1. Monitoring the performance impact of these changes in real-world usage.
  2. If needed, fine-tune the willChange properties based on performance profiling results.
  3. Ensuring that these optimizations are consistently applied across other similar transition components in the codebase.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c06802f and e78e6ca.

📒 Files selected for processing (1)
  • packages/components/modal/src/modal-transition.ts (2 hunks)
🔇 Additional comments (1)
packages/components/modal/src/modal-transition.ts (1)

8-8: Approved: Good performance optimization for modal entry

The addition of willChange: "auto" to the enter state is a smart optimization. This hints to the browser that it should prepare for changes in any animatable properties during the modal's entry animation. It's likely to help with the blurry text issue mentioned in #3817 by encouraging the browser to create a new compositing layer, which can lead to sharper text rendering.

Copy link
Member

@ryo-manba ryo-manba left a comment

Choose a reason for hiding this comment

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

I've made some minor comments, but overall, looks good.

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

🧹 Outside diff range and nitpick comments (4)
packages/utilities/shared-utils/src/functions.ts (4)

23-25: Approve changes with a minor suggestion

The updates to the capitalize function improve its behavior by handling falsy inputs and ensuring consistent capitalization. However, consider using a more descriptive parameter name than s.

Consider renaming the parameter for better clarity:

-export const capitalize = (s: string) => {
-  return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : "";
+export const capitalize = (text: string) => {
+  return text ? text.charAt(0).toUpperCase() + text.slice(1).toLowerCase() : "";
};

212-218: Approve uniqBy function with a type safety improvement suggestion

The uniqBy function is a valuable addition to the utility library. It efficiently filters unique elements based on a flexible iteratee. However, we can improve type safety by utilizing the Iteratee<T> type defined earlier.

Consider updating the function signature for better type safety:

-export function uniqBy<T>(arr: T[], iteratee: any) {
+export function uniqBy<T>(arr: T[], iteratee: Iteratee<T>) {
   if (typeof iteratee === "string") {
     iteratee = (item: T) => item[iteratee as keyof T];
   }

   return arr.filter((x, i, self) => i === self.findIndex((y) => iteratee(x) === iteratee(y)));
 }

254-256: Approve kebabCase function with suggestions for improvement

The kebabCase function provides a simple and effective way to convert strings to kebab-case. However, there are a few edge cases that the current implementation doesn't handle.

Consider the following improvements to handle more cases:

  1. Handle PascalCase strings.
  2. Handle multiple consecutive uppercase letters.
  3. Handle non-alphanumeric characters.

Here's an improved implementation:

export const kebabCase = (s: string) => {
  return s
    .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
    .replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2')
    .replace(/[^a-zA-Z0-9]/g, '-')
    .toLowerCase();
};

This implementation will correctly handle cases like:

  • "fooBar" → "foo-bar"
  • "FooBar" → "foo-bar"
  • "FOOBar" → "foo-bar"
  • "foo_bar" → "foo-bar"

269-276: Approve mapKeys function with type improvement suggestions

The mapKeys function is a useful addition that efficiently transforms object keys. The implementation is concise and effective.

To improve type safety and clarity, consider updating the type annotations:

export const mapKeys = <T extends Record<string, unknown>, U extends string | number | symbol>(
  obj: T,
  iteratee: (value: T[keyof T], key: string) => U
): Record<U, T[keyof T]> => {
  return Object.fromEntries(
    Object.entries(obj).map(([key, value]) => [iteratee(value, key), value])
  ) as Record<U, T[keyof T]>;
};

This updated signature:

  1. Ensures that the input object has string keys and any value type.
  2. Allows the iteratee to return any valid object key type (string, number, or symbol).
  3. Correctly types the return object based on the iteratee's return type and the original value types.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e78e6ca and 43bbb31.

📒 Files selected for processing (1)
  • packages/utilities/shared-utils/src/functions.ts (6 hunks)
🔇 Additional comments (5)
packages/utilities/shared-utils/src/functions.ts (5)

11-12: LGTM: Well-defined Iteratee type alias

The Iteratee<T> type alias is a good addition. It provides flexibility by allowing either a function or a key of T to be used as an iteratee in various utility functions. This enhances type safety and improves the overall API design.


178-196: LGTM: Well-implemented debounce function

The debounce function is a great addition to the utility library. It's well-implemented with proper TypeScript generics, maintaining the original function's context and arguments. The implementation follows best practices for debouncing and provides a useful tool for performance optimization in event-driven scenarios.


342-391: LGTM: Well-implemented intersectionBy function

The intersectionBy function is a robust and efficient implementation for computing the intersection of multiple arrays based on a transformed value. Key points:

  1. Proper use of the Iteratee<T> type enhances type safety.
  2. Efficient use of Sets for performance optimization.
  3. Thorough error handling for invalid inputs.
  4. Correct handling of both function and string iteratees.

The implementation is well-thought-out and should perform well for various use cases.


Line range hint 1-391: Summary: Excellent enhancements to the utility functions

This PR significantly improves the functions.ts file by adding several new utility functions and enhancing existing ones. The changes align well with the PR objectives of optimizing the codebase:

  1. The new functions (debounce, uniqBy, omit, kebabCase, mapKeys, get, and intersectionBy) provide valuable tools for common programming tasks, potentially reducing the need for external libraries.
  2. Existing functions have been improved and better documented, enhancing maintainability.
  3. Type safety has been improved in most areas, particularly with the introduction of the Iteratee<T> type.

These enhancements should contribute to a more efficient and maintainable codebase. The utility functions are well-implemented and should help reduce bundle size by eliminating the need for some external dependencies.

Minor suggestions for further improvement:

  1. Consider implementing deep cloning in the omit function if needed for your use cases.
  2. Enhance the kebabCase function to handle more edge cases.
  3. Further improve type annotations in some functions, as suggested in the individual reviews.

Overall, these changes represent a significant improvement to the shared utilities and should positively impact the project's performance and maintainability.


234-242: Approve omit function with a note on shallow copying

The omit function is a well-implemented utility that creates a new object by omitting specified keys. The use of TypeScript generics and the Omit utility type ensures type safety.

Note that the current implementation creates a shallow copy of the object. This is sufficient for most use cases, but be aware that nested objects will still share references with the original object. If deep cloning is required for your use case, consider using a deep clone utility or library.

To verify the shallow copy behavior, you can run the following test:

This test will demonstrate the shallow copy behavior of the omit function.

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

🧹 Outside diff range and nitpick comments (2)
apps/docs/components/docs/components/codeblock.tsx (1)

Line range hint 125-134: Optimize debounce implementation to prevent memory leaks.

The current implementation recreates the debounced function on every render. Consider:

  1. Moving the debounced function creation outside the effect
  2. Ensuring pending debounced calls are cancelled in cleanup
+ const debouncedHandleSelectionChange = React.useMemo(
+   () => debounce(handleSelectionChange, 1000),
+   []
+ );

  useEffect(() => {
-   const debouncedHandleSelectionChange = debounce(handleSelectionChange, 1000);
    document.addEventListener("selectionchange", debouncedHandleSelectionChange);

    return () => {
+     debouncedHandleSelectionChange.cancel?.();
      document.removeEventListener("selectionchange", debouncedHandleSelectionChange);
    };
-  }, []);
+  }, [debouncedHandleSelectionChange]);
apps/docs/components/navbar.tsx (1)

Line range hint 210-214: Add error handling for tracking events

While the tracking implementation is thorough, consider adding error handling to prevent potential issues from affecting the user experience.

  const handlePressNavbarItem = (name: string, url: string) => {
-   trackEvent("NavbarItem", {
-     name,
-     action: "press",
-     category: "navbar",
-     data: url,
-   });
+   try {
+     trackEvent("NavbarItem", {
+       name,
+       action: "press",
+       category: "navbar",
+       data: url,
+     });
+   } catch (error) {
+     console.error("Failed to track navbar interaction:", error);
+   }
  };

Also applies to: 221-225, 232-236

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 43bbb31 and 32274e7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • apps/docs/components/docs/components/codeblock.tsx (1 hunks)
  • apps/docs/components/navbar.tsx (4 hunks)
  • apps/docs/components/sandpack/use-sandpack.ts (2 hunks)
  • apps/docs/package.json (1 hunks)
  • packages/components/accordion/package.json (3 hunks)
  • packages/components/autocomplete/package.json (2 hunks)
  • packages/components/button/package.json (1 hunks)
  • packages/components/calendar/package.json (2 hunks)
  • packages/components/card/package.json (1 hunks)
  • packages/components/dropdown/package.json (2 hunks)
  • packages/components/modal/package.json (3 hunks)
  • packages/components/navbar/package.json (2 hunks)
  • packages/components/popover/package.json (3 hunks)
  • packages/components/select/package.json (2 hunks)
  • packages/components/snippet/package.json (1 hunks)
  • packages/components/tabs/package.json (2 hunks)
  • packages/components/tabs/src/tab.tsx (1 hunks)
  • packages/components/tooltip/package.json (3 hunks)
  • packages/core/react/package.json (1 hunks)
  • packages/core/system/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/components/tabs/src/tab.tsx
🚧 Files skipped from review as they are similar to previous changes (17)
  • apps/docs/components/sandpack/use-sandpack.ts
  • apps/docs/package.json
  • packages/components/accordion/package.json
  • packages/components/autocomplete/package.json
  • packages/components/button/package.json
  • packages/components/calendar/package.json
  • packages/components/card/package.json
  • packages/components/dropdown/package.json
  • packages/components/modal/package.json
  • packages/components/navbar/package.json
  • packages/components/popover/package.json
  • packages/components/select/package.json
  • packages/components/snippet/package.json
  • packages/components/tabs/package.json
  • packages/components/tooltip/package.json
  • packages/core/react/package.json
  • packages/core/system/package.json
🔇 Additional comments (4)
apps/docs/components/docs/components/codeblock.tsx (2)

Line range hint 164-165: LGTM: Clean props handling with omit.

The implementation correctly removes the 'key' prop before spreading while maintaining unique keys through getUniqueID. This is a good practice to avoid React key warnings while ensuring proper component rendering.

Also applies to: 189-190


4-4: Verify the behavior of the new utility functions.

The change from lodash to @nextui-org/shared-utils aligns with the PR's optimization goals. However, we should verify that the new implementations maintain the same behavior, especially for:

  • The debounce timing in the selection change handler
  • The omit function's handling of props spreading
✅ Verification successful

The utility functions implementation is safe to use

The implementation of both debounce and omit in @nextui-org/shared-utils follows standard patterns and maintains expected behavior:

  • The debounce function properly handles timeouts and function context, matching the behavior needed for the selection change handler (1000ms delay)
  • The omit function correctly removes specified keys from objects, which is suitable for the props spreading use cases in the component

The usage in the codeblock component aligns well with these implementations:

  • debounce is used with the correct timing for selection changes
  • omit is used appropriately for filtering out specific props before spreading
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of debounce and omit in shared-utils

# Test 1: Check the debounce implementation
echo "Checking debounce implementation..."
ast-grep --pattern 'export function debounce'

# Test 2: Check the omit implementation
echo "Checking omit implementation..."
ast-grep --pattern 'export function omit'

# Test 3: Check for any other components using these utilities
echo "Checking other components using these utilities..."
rg "import.*\{.*(debounce|omit).*\}.*from.*@nextui-org/shared-utils"

Length of output: 842


Script:

#!/bin/bash
# Let's check the actual implementations to verify behavior

# Check the shared-utils implementation
echo "Searching for shared-utils implementations..."
fd "shared-utils" --type f --exec rg -A 10 "export (const|function) (debounce|omit)"

# Check usage in codeblock component
echo "Checking usage in codeblock component..."
rg -A 5 "(debounce|omit)" apps/docs/components/docs/components/codeblock.tsx

Length of output: 1478


Script:

#!/bin/bash
# Let's find the actual implementation in shared-utils package
echo "Looking for shared-utils package implementation..."
fd -t f -e ts -e js . --full-path "**/shared-utils/**" --exec cat {}

# Also check if there are any tests for these utilities
echo "Looking for related tests..."
fd -t f -e test.ts -e test.js -e spec.ts -e spec.js . --full-path "**/shared-utils/**" --exec cat {}

Length of output: 567


Script:

#!/bin/bash
# Let's try a different approach to find the shared-utils package
echo "Finding shared-utils package location..."
fd shared-utils

# Once we find it, let's look for the specific files
echo "Looking for utility implementations..."
rg -A 10 "^export (const|function) (debounce|omit)" --type ts

Length of output: 3337

apps/docs/components/navbar.tsx (2)

199-199: LGTM: Effective optimization of includes checks

The replacement of lodash's includes with native JavaScript includes is a good optimization that reduces bundle size while maintaining the same functionality.

Also applies to: 210-210, 221-221, 232-232


Line range hint 313-332: Verify text rendering in version dropdown animation

Given the reported issues with blurry text during animations (#3817, #2288), we should verify that the AnimatePresence transition doesn't cause similar text rendering issues.

✅ Verification successful

Let me gather more specific information about the animation implementation in the navbar component.


Based on the search results, I can now provide a final response:

No text rendering issues expected with current animation implementation

The AnimatePresence animation in the navbar only uses opacity transitions (0 to 1) without any transform properties or percentage-based values that could cause text blur. The implementation is using simple fade animations that don't affect text rendering quality.

  • The motion.div at L196-202 only includes opacity in its animation properties: animate={{opacity: 1}} exit={{opacity: 0}} initial={{opacity: 0}}
  • No transform properties or complex animations are used in the version display component
  • The CSS files only show transform usage in unrelated components (nprogress.css)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any will-change or transform properties that might affect text rendering
rg -g '*.{css,scss}' 'will-change|transform:'

# Look for any framer-motion animation configurations that might use percentage-based transforms
ast-grep --pattern 'animate = {
  $$$
  opacity: $_
  $$$
}'

Length of output: 330


Script:

#!/bin/bash
# Search for AnimatePresence usage in navbar and related components
rg -A 5 "AnimatePresence" apps/docs/components/navbar.tsx

# Look for motion component configurations that might affect text rendering
ast-grep --pattern 'motion.$_ = {
  $$$
  transition: $_
  $$$
}'

# Check for any transform-related styles in the navbar
rg -g '*.{css,scss,tsx}' 'transform' apps/docs/components/navbar

Length of output: 1102

@jrgarciadev jrgarciadev merged commit 3f0d81b into canary Nov 4, 2024
8 checks passed
@jrgarciadev jrgarciadev deleted the refactor/optimisation branch November 4, 2024 20:47
ryo-manba pushed a commit that referenced this pull request Nov 6, 2024
* refactor: replace lodash with native approaches

* refactor(deps): update framer-motion versions

* feat(utilities): add @nextui-org/dom-animation

* refactor(components): load domAnimation dynamically

* refactor(deps): add @nextui-org/dom-animation

* fix(utilities): relocate index.ts

* feat(changeset): framer motion optimization

* chore(deps): bump framer-motion version

* fix(docs): conflict issue

* refactor(hooks): remove the unnecessary this aliasing

* refactor(utilities): remove the unnecessary this aliasing

* chore(docs): remove {} so that it won't be true all the time

* chore(dom-animation): end with new line

* refactor(hooks): use debounce from `@nextui-org/shared-utils`

* chore(deps): add `@nextui-org/shared-utils`

* refactor: move mapKeys logic to `@nextui-org/shared-utils`

* refactor: use `get` from `@nextui-org/shared-utils`

* refactor(docs): use `get` from `@nextui-org/shared-utils`

* refactor(shared-utils): mapKeys

* chore(deps): bump framer-motion version

* chore(deps): remove lodash

* refactor(docs): use intersectionBy from shared-utils

* feat(shared-utils): add intersectionBy

* chore(dom-animation): remove extra blank line

* refactor(shared-utils): revise intersectionBy

* fix(modal): add willChange

* refactor(shared-utils): add comments

* fix: build & tests

---------

Co-authored-by: Junior Garcia <[email protected]>
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.

[BUG] - Blurry text in chrome when modal opens [BUG] - BLURRY ON SIZE ANIMATIONS
3 participants