-
-
Notifications
You must be signed in to change notification settings - Fork 692
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: address search bar issue in the navbar #3447
Conversation
WalkthroughThe changes in this pull request enhance the Changes
Assessment against linked issues
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3447 +/- ##
=======================================
Coverage 77.22% 77.22%
=======================================
Files 21 21
Lines 663 663
=======================================
Hits 512 512
Misses 151 151 ☔ View full report in Codecov by Sentry. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3447--asyncapi-website.netlify.app/ |
There was a problem hiding this 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/AlgoliaSearch.tsx (1)
315-316
: Consider architectural improvements for better maintainabilityTo prevent similar issues in the future and improve component reliability:
- Consider adding proper TypeScript types for the function children
- Add error boundaries to catch render failures
- Add documentation about the expected children format
Here's a suggested improvement for the types:
type SearchButtonChildren = React.ReactNode | (({ actionKey }: { actionKey: { shortKey: string; key: string } }) => React.ReactNode); interface ISearchButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'children'> { children?: SearchButtonChildren; indexName?: string; }And add JSDoc documentation:
/** * SearchButton component that renders a button to trigger the search modal. * @param props - The component props * @param props.children - Can be either a ReactNode or a function that receives actionKey and returns ReactNode * @param props.indexName - Optional index name for Algolia search * @example * // Using with static children * <SearchButton> * <IconLoupe /> * </SearchButton> * * // Using with function children * <SearchButton> * {({ actionKey }) => ( * <> * <IconLoupe /> * <span>Search ({actionKey.shortKey}+K)</span> * </> * )} * </SearchButton> */
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
components/AlgoliaSearch.tsx
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
components/AlgoliaSearch.tsx (1)
Learnt from: amanbhoria
PR: asyncapi/website#3373
File: components/AlgoliaSearch.tsx:313-313
Timestamp: 2024-11-12T06:59:33.852Z
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.
🔇 Additional comments (2)
components/AlgoliaSearch.tsx (2)
315-316
:
Fix useEffect implementation to handle children updates properly
The current implementation has several issues that could explain why the IconLoupe wasn't rendering:
- The useEffect hook runs only once due to empty dependencies array, so it won't update when children prop changes
- Missing dependencies could cause stale closures
- No type checking before function call could cause runtime errors
Apply this fix to ensure proper rendering and updates:
useEffect(() => {
if (typeof children === 'function') {
setChildren(children({ actionKey }));
} else {
setChildren(children);
}
- }, []);
+ }, [children, actionKey]);
Additionally, consider adding type safety:
useEffect(() => {
- if (typeof children === 'function') {
+ if (children && typeof children === 'function') {
setChildren(children({ actionKey }));
} else {
setChildren(children);
}
}, [children, actionKey]);
Let's verify if this component is used with function children elsewhere:
✅ Verification successful
Dependencies in useEffect are necessary for proper functionality
The search results confirm that the SearchButton component is used with function children in Hero.tsx
:
<SearchButton className='...'>
{({ actionKey }) => (
// ...
)}
</SearchButton>
This validates that both dependencies (children
and actionKey
) are actively used in the codebase and must be included in the useEffect dependencies array to ensure proper updates when either prop changes.
The fix proposed in the original review is correct:
useEffect(() => {
if (typeof children === 'function') {
setChildren(children({ actionKey }));
} else {
setChildren(children);
}
- }, []);
+ }, [children, actionKey]);
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for SearchButton usage with function children
ast-grep --pattern 'SearchButton $$$>
{({ actionKey }) => $$$}
</SearchButton>'
Length of output: 83
Script:
#!/bin/bash
# Let's try a broader search for SearchButton usage
rg -l "SearchButton" --type tsx --type jsx
# Then look for any function children pattern in those files
rg "SearchButton.*{.*=>.*}" -A 2 --type tsx --type jsx
Length of output: 247
Script:
#!/bin/bash
# Search for files containing SearchButton
rg -l "SearchButton"
# Then look for any function children pattern with proper escaping
rg "SearchButton.*\{.*=>" -A 2
Length of output: 257
Script:
#!/bin/bash
# Let's examine how SearchButton is used in these files
for file in components/AlgoliaSearch.tsx components/navigation/NavBar.tsx components/navigation/DocsNavWrapper.tsx components/navigation/MobileNavMenu.tsx components/navigation/DocsMobileMenu.tsx components/Hero.tsx; do
echo "=== $file ==="
rg "SearchButton" -B 1 -A 1 "$file"
done
Length of output: 6151
315-316
: Verify the fix resolves the IconLoupe rendering issue
While the changes address the children handling, please verify:
- That IconLoupe renders correctly after these changes
- That the search functionality works as expected
- That keyboard shortcuts still work properly
Let's verify the IconLoupe component usage:
✅ Verification successful
IconLoupe implementation and search functionality are properly integrated
The verification shows that:
- IconLoupe is correctly implemented and used across multiple components
- The search functionality includes proper keyboard shortcuts (/, Cmd/Ctrl+K)
- The children state management in AlgoliaSearch is correctly handling the IconLoupe component
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for IconLoupe imports and usage
rg "IconLoupe" --type tsx --type ts
# Search for other icon components that might be affected
rg "Icon.*" --type tsx --type ts
Length of output: 126
Script:
#!/bin/bash
# Search for IconLoupe imports and usage without file type restrictions
rg "IconLoupe"
# Search for the AlgoliaSearch component implementation
ast-grep --pattern 'const AlgoliaSearch = $_'
# Check if there are any test files related to search functionality
fd -g "*search*.test.*"
fd -g "*Search*.test.*"
Length of output: 910
Script:
#!/bin/bash
# Check the Loupe icon implementation
cat components/icons/Loupe.tsx
# Check the AlgoliaSearch component for icon usage
cat components/AlgoliaSearch.tsx
# Look for any search-related keyboard shortcuts
rg "keyboard|keydown|keypress" components/AlgoliaSearch.tsx
Length of output: 10872
/rtm |
Thanks @allenhack638 for the PR 🎆 |
Description
This PR fixes the issue where the SearchBar was not showing on the navbar. It ensures the search bar is correctly rendered and behaves as expected.
Fixes
Fixes #3371 : [BUG] SearchBar is not showing on the navbar
Summary by CodeRabbit
SearchButton
component to support dynamic rendering of its content based on the action key.children
prop, allowing for both functional and static content display.