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

Performance: lazy load the Emoji & SearchModal components #12479

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Mar 18, 2024

Description

Lazy load these components to separate these libs into their own chunks of js bundles.

Currently, they are part of the app (main) bundle that is loaded by all the pages and blocking the main thread. We can load these libs async and minimize the work done in it.

app.js bundle before (~1.01Mb parsed):
image

app.js bundle after (~788Kb parsed):
image

Summary by CodeRabbit

  • Performance Improvements
    • Improved loading times by implementing dynamic imports for the Emoji and Search Modal components, enhancing code splitting and lazy loading.

Copy link
Contributor

coderabbitai bot commented Mar 18, 2024

Walkthrough

The recent modifications involve the adoption of dynamic imports for specific components within the project. This approach has been applied to the Twemoji component in Emoji.tsx and the SearchModal in the Search component. By transitioning to dynamic imports, the project benefits from improved code splitting and lazy loading, enhancing performance by loading these components only when necessary.

Changes

File Path Change Summary
src/components/Emoji.tsx
src/components/Search/index.tsx
Changed import of Twemoji to dynamic using next/dynamic in Emoji.tsx. Added dynamic import for SearchModal in Search/index.tsx for better code splitting and lazy loading.

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

netlify bot commented Mar 18, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit a2f1c30
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65f86196964daa00089e9172
😎 Deploy Preview https://deploy-preview-12479--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between dd0f529 and c7082fc.
Files selected for processing (2)
  • src/components/Emoji.tsx (1 hunks)
  • src/components/Search/index.tsx (2 hunks)
Additional comments: 1
src/components/Search/index.tsx (1)
  • 28-28: The implementation of dynamic import for SearchModal using next/dynamic is correctly done and aligns with the objective of lazy loading for performance optimization. Ensure thorough testing, especially for any issues related to modal display, interaction, or any unexpected behavior in development and production environments.
Verification successful

The verification process did not find any reported issues related to modal display, interaction, or unexpected behavior in the source code after implementing dynamic import for SearchModal. This suggests that the implementation is correctly done without introducing known problems. However, it's essential to conduct thorough testing in both development and production environments to ensure that no issues arise from this change.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if there are any reported issues related to modal display, interaction, or unexpected behavior in development and production environments after implementing dynamic import.
grep -Ri "modal display issue" src/ || echo "No modal display issues reported."
grep -Ri "modal interaction issue" src/ || echo "No modal interaction issues reported."
grep -Ri "unexpected behavior" src/ || echo "No unexpected behavior issues reported."

Length of output: 368

Comment on lines 7 to 9
const Twemoji = dynamic(() =>
import("react-emoji-render").then((mod) => mod.Twemoji)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The implementation of dynamic import for Twemoji using next/dynamic appears correct; however, the discovery of a comment mentioning a "hydration mismatch" issue within src/components/Emoji.tsx suggests that there might be potential issues related to the dynamic import. It's crucial to address this hydration mismatch concern to ensure the component functions as expected without causing any unexpected behavior in development and production environments.

Analysis chain

The implementation of dynamic import for Twemoji using next/dynamic is correctly done and aligns with the objective of lazy loading for performance optimization. Ensure thorough testing, especially for hydration mismatches or any unexpected behavior in development and production environments.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if there are any reported issues related to hydration mismatches or unexpected behavior in development and production environments after implementing dynamic import.
grep -Ri "hydration mismatch" src/ || echo "No hydration mismatch issues reported."
grep -Ri "unexpected behavior" src/ || echo "No unexpected behavior issues reported."

Length of output: 265

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c7082fc and a2f1c30.
Files selected for processing (1)
  • src/components/Emoji.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/Emoji.tsx

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

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

Lgtm! Thanks @pettinarip!

@wackerow wackerow merged commit 310d76e into dev Mar 20, 2024
10 checks passed
@wackerow wackerow deleted the lazy-load-modules branch March 20, 2024 18:00
This was referenced Mar 26, 2024
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.

2 participants