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: algolia search icon on homepage #3373

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

amanbhoria
Copy link

@amanbhoria amanbhoria commented Nov 7, 2024

Fix for the issue - #3371

Before: Algolia search icon went missing.

After:
image

Fix: sending the expected value in children prop

image

Summary by CodeRabbit

  • Refactor

    • Simplified processing of the children prop in the SearchButton component for improved readability.
  • Bug Fixes

    • Maintained existing functionality and error handling of the AlgoliaSearch component, ensuring consistent search operations.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request focus on the SearchButton component within the AlgoliaSearch.tsx file. The logic for processing the children prop has been simplified, removing the conditional check for function invocation and streamlining the state assignment. The overall structure and functionality of the AlgoliaSearch component, including its context and event management, remain intact, with no alterations to exported or public entities.

Changes

File Change Summary
components/AlgoliaSearch.tsx Simplified the processing of the children prop in the SearchButton component by removing the conditional check for function invocation.

Suggested labels

ready-to-merge

Suggested reviewers

  • derberg
  • akshatnema
  • magicmatatjahu
  • Mayaleeeee
  • asyncapi-bot-eve
  • sambhavgupta0705
  • anshgoyalevil

Poem

In the search for joy, we hop and play,
A button now simpler, brightens the day.
With children in tow, no checks to confound,
A leap of delight in the code we have found! 🐇✨


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

netlify bot commented Nov 7, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 116ab5f
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67463e7ba7cf08000873718b
😎 Deploy Preview https://deploy-preview-3373--asyncapi-website.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.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Nov 7, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 33
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3373--asyncapi-website.netlify.app/

@amanbhoria amanbhoria changed the title fix: Algolia search icon on homepage fix: algolia search icon on homepage Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.77%. Comparing base (7669160) to head (116ab5f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3373   +/-   ##
=======================================
  Coverage   67.77%   67.77%           
=======================================
  Files          21       21           
  Lines         664      664           
=======================================
  Hits          450      450           
  Misses        214      214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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 (1)
components/navigation/NavBar.tsx (1)

Line range hint 82-85: Consider applying the same fix to mobile search button.

For consistency, consider using the same function-based approach for the IconLoupe in the mobile search button implementation.

 <SearchButton
   className='flex items-center space-x-2 rounded-md p-2 text-left text-gray-400 transition duration-150 ease-in-out hover:bg-gray-100 hover:text-gray-500 focus:bg-gray-100 focus:text-gray-500 focus:outline-none'
   aria-label='Open Search'
 >
-  <IconLoupe />
+  {() => <IconLoupe />}
 </SearchButton>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1071c76 and c364685.

📒 Files selected for processing (1)
  • components/navigation/NavBar.tsx (1 hunks)
🔇 Additional comments (2)
components/navigation/NavBar.tsx (2)

226-226: LGTM! Fix for Algolia search icon rendering.

The change correctly implements the children prop as a function, which is the expected pattern for the Algolia SearchButton component.


Line range hint 82-85: Verify SearchButton children prop requirements.

Let's verify the SearchButton component's implementation to ensure consistent usage of the children prop.

Also applies to: 226-228

✅ Verification successful

SearchButton component's children prop is correctly implemented

Based on the codebase analysis, the SearchButton component in components/AlgoliaSearch.tsx accepts children as either React.ReactNode or a render prop function with actionKey parameter. The usage in NavBar.tsx is consistent with this implementation:

  • Line 226-228 uses IconLoupe as children directly
  • Other usages in the codebase demonstrate both patterns:
    • Direct children: <IconLoupe />
    • Render prop: {({ actionKey }) => <IconLoupe />}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SearchButton component definition and usage
echo "Searching for SearchButton component definition..."
rg -A 10 "export.*SearchButton" --type tsx

echo "Searching for other SearchButton usages..."
rg -A 3 "<SearchButton" --type tsx

Length of output: 343


Script:

#!/bin/bash
# Search for SearchButton component definition and usage with correct file extensions
echo "Searching for SearchButton component definition..."
rg -A 10 "export.*SearchButton" --type ts --type tsx --type jsx --type js

echo "Searching for SearchButton usages..."
rg -A 3 "<SearchButton" --type ts --type tsx --type jsx --type js

# Also try finding the file by name
echo "Finding SearchButton related files..."
fd -e ts -e tsx -e js -e jsx "SearchButton"

Length of output: 522


Script:

#!/bin/bash
# Try simpler search patterns without file type restrictions
echo "Searching for SearchButton definition..."
rg -l "SearchButton"

echo "Searching for SearchButton component content..."
rg -A 10 "SearchButton"

# Try finding any file containing 'search' case-insensitive
echo "Finding search-related files..."
fd -i search

Length of output: 16028

@@ -223,7 +223,7 @@ export default function NavBar({ className = '', hideLogo = false }: NavBarProps
className='mr-2 flex items-center space-x-2 rounded-md p-2 text-left text-gray-400 transition duration-150 ease-in-out hover:bg-gray-100 hover:text-gray-500 focus:bg-gray-100 focus:text-gray-500 focus:outline-none'
aria-label='Open Search'
>
<IconLoupe />
{() => <IconLoupe />}
Copy link
Member

Choose a reason for hiding this comment

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

@amanbhoria can you please elaborate this change a little

Copy link
Author

Choose a reason for hiding this comment

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

@sambhavgupta0705 As you can see in the useEffect, type of children is expected as a function, but it was a node earlier. That's the reason why Algolia search icon was not visible.

image

Copy link
Member

Choose a reason for hiding this comment

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

@amanbhoria Can we change the useEffect function then, to fix this rendering?

Copy link
Author

Choose a reason for hiding this comment

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

image

@akshatnema As it can handle both the searches on landing page simultaneously. Can we do something like that?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, can you please try that and see if we are facing any errors or not.

Copy link
Author

Choose a reason for hiding this comment

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

As far as the search's concern, everything seems to be working.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c364685 and 6100fab.

📒 Files selected for processing (1)
  • components/AlgoliaSearch.tsx (1 hunks)

if (typeof children === 'function') {
setChildren(children({ actionKey }));
}
setChildren(typeof children === 'function' ? children({ actionKey }) : children);
Copy link

@coderabbitai coderabbitai bot Nov 11, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing dependencies to useEffect.

The effect uses children and actionKey but they're not included in the dependency array. This violates the React hooks exhaustive deps rule and could lead to stale closures.

Apply this fix:

    setChildren(typeof children === 'function' ? children({ actionKey }) : children);
-  }, []);
+  }, [children, actionKey]);

Note: If you need the effect to run only once, consider memoizing the children and actionKey values using useMemo.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setChildren(typeof children === 'function' ? children({ actionKey }) : children);
setChildren(typeof children === 'function' ? children({ actionKey }) : children);
}, [children, actionKey]);

Copy link
Author

Choose a reason for hiding this comment

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

the component is being rendered on every button click on Search and so as useEffect. so what's the need to add these parameters in the dependency array? It doesn't make any sense to me

Copy link

Choose a reason for hiding this comment

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

@amanbhoria, understood. If the component re-renders on every button click and the useEffect runs accordingly, then adding these dependencies might not be necessary in this case. Thank you for the clarification.


✏️ Learnings added
Learnt from: amanbhoria
PR: asyncapi/website#3373
File: components/AlgoliaSearch.tsx:313-313
Timestamp: 2024-11-11T21:30:32.237Z
Learning: In the `SearchButton` component within `components/AlgoliaSearch.tsx`, if the component re-renders on every button click and the `useEffect` runs accordingly, adding dependencies to the dependency array might not be necessary.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member

@anshgoyalevil anshgoyalevil left a comment

Choose a reason for hiding this comment

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

Thanks @amanbhoria

@anshgoyalevil
Copy link
Member

@amanbhoria The solution is working but I am seeing a lot of re-renders in the Chrome DevTools.
image

These were quite low on the master branch deployment

@amanbhoria
Copy link
Author

@anshgoyalevil Did you see these logs when running the project locally? I’m only seeing two render logs in the dev tools. Could you help me with this?

@akshatnema
Copy link
Member

@amanbhoria There are some issues with the homepage. Please check these errors first -

image

Copy link
Member

@akshatnema akshatnema left a comment

Choose a reason for hiding this comment

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

Requesting changes as these changes shouldn't be merged to master now.

@amanbhoria
Copy link
Author

Hi, I'm back. Let me look into this. Will get back to you

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.

5 participants