-
Notifications
You must be signed in to change notification settings - Fork 130
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 hydration error in Header.js #674
Fix hydration error in Header.js #674
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe changes in this pull request primarily focus on enhancing the navigation functionality within the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
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
CodeRabbit Configuration File (
|
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.
Yeah! You did it 🎉 Now, Relax 😉, Grab a drink ☕, and wait for the maintainers to check your contributions. Meanwhile, you can discuss on other issues and solve them 😀. Thank You 😃!
Meanwhile you can also discuss about the project in our Discord Server 😀
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: 1
🧹 Outside diff range and nitpick comments (2)
Website/app/Header.js (2)
49-51
: Remove unnecessarysetOpen
prop fromNavLink
in desktop navigationIn the desktop navigation, the
NavLink
components are being passedsetOpen={setOpen}
, but thesetOpen
prop is primarily used for controlling the mobile navigation state. In the desktop layout, the navigation menu is always visible, and there's no need to close it.Consider removing
setOpen={setOpen}
fromNavLink
in the desktop navigation to simplify the code.Apply this diff:
// In the desktop navigation at lines 154-164 <div className="hidden md:flex mr-20 "> - <NavLink to="/#" cn="mx-4 flex" setOpen={setOpen}> + <NavLink to="/#" cn="mx-4 flex"> HOME </NavLink> - <NavLink to="/about" cn="mx-4 flex" setOpen={setOpen}> + <NavLink to="/about" cn="mx-4 flex"> ABOUT </NavLink> - <NavLink to="/download" cn="mx-4 flex" setOpen={setOpen}> + <NavLink to="/download" cn="mx-4 flex"> DOWNLOAD </NavLink> - <NavLink to="/contact" cn="mx-4 flex" setOpen={setOpen}> + <NavLink to="/contact" cn="mx-4 flex"> CONTACT </NavLink> </div>Also applies to: 56-58, 63-65, 154-164
Line range hint
27-73
: Simplify navigation logic by removing unnecessary functionsWith the adoption of the
<Link>
component and client-side routing, thehandleNavLinkClick
function and passingsetOpen
to everyNavLink
may no longer be necessary.Consider refactoring
MobileNav
andNavLink
to streamline your navigation:
- Remove the
handleNavLinkClick
function.- Pass
setOpen
directly toonClick
handlers where needed.- Ensure
setOpen(false)
is called after navigation to close the mobile menu.Apply this diff as a starting point:
-function handleNavLinkClick(to, setOpen) { - if (window.location.pathname === to) { - setOpen(false); - } else { - window.location.href = to; - } -} - function NavLink({ to, children, cn }) { return ( - <button - onClick={() => handleNavLinkClick(to, setOpen)} + <Link + href={to} + onClick={() => setOpen(false)} className={`text-gray-900 hover:text-black ${cn}`} > {children} - </button> + </Link> ); }Ensure that
setOpen(false)
is called appropriately to close the mobile navigation after a link is clicked.
@drippypop Awesome work 👏. |
@SaptarshiSarkar12 fixing it right now |
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: 3
🧹 Outside diff range and nitpick comments (3)
Website/app/Header.js (3)
156-166
: LGTM: Header component changes with minor suggestionThe modifications to the
Header
component, including passingsetOpen
toMobileNav
and eachNavLink
, are consistent with the changes made to other components. This implementation effectively addresses the issue of the navigation bar not closing when a link is clicked.For consistency, consider updating the "HOME" NavLink to use a lowercase path:
- <NavLink to="/#" cn="mx-4 flex" setOpen={setOpen}> + <NavLink to="/" cn="mx-4 flex" setOpen={setOpen}>This change aligns with the path format used in other NavLink components and removes the unnecessary hash.
Line range hint
137-139
: Use functional update forsetOpen
The current implementation directly toggles the
open
state. For consistency and to avoid potential issues with state updates, it's recommended to use the functional form ofsetOpen
.Update the click handler as follows:
- onClick={() => { - setOpen(!open); - }} + onClick={() => setOpen(prevOpen => !prevOpen)}This change ensures that the state update is based on the previous state, which is a more reliable approach, especially when dealing with asynchronous state updates.
Line range hint
1-187
: Overall good implementation with suggestions for improvementThe changes in this file effectively address the hydration error and the issue of the navigation bar not closing when clicking on the current page. The implementation of
handleNavLinkClick
and the modifications toNavLink
,MobileNav
, andHeader
components work together to solve the described problems.To further improve the code quality and consistency:
- Consider using a linter (e.g., ESLint) with a consistent configuration to standardize code style, including quotation marks usage.
- Implement the suggestions provided in the previous comments, particularly:
- Updating the router import for the Next.js App Router
- Refactoring
handleNavLinkClick
for better Next.js integration- Preserving the
Link
component inNavLink
for SEO and accessibility- Using a functional update for
setOpen
in the hamburger button click handlerThese changes will enhance the overall quality, maintainability, and performance of the component.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- Website/app/Header.js (4 hunks)
🔇 Additional comments (1)
Website/app/Header.js (1)
29-29
: LGTM: MobileNav changesThe modifications to the
MobileNav
component, including passing thesetOpen
prop to eachNavLink
, effectively address the issue of the navigation bar not closing when a link is clicked. This implementation aligns well with the PR objectives.Also applies to: 51-51, 58-58, 65-65
@drippypop Please fix the reviews and errors by GitHub Advanced Security bot and Coderabbit AI bot. |
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: 3
🧹 Outside diff range and nitpick comments (2)
Website/app/Header.js (2)
155-165
: LGTM with suggestion: NavLink updates in main navigationThe addition of the
setOpen
prop to theNavLink
components in the main navigation is consistent with the earlier changes and improves functionality.However, consider optimizing this for desktop views:
- You could conditionally pass the
setOpen
prop based on the viewport size:const isMobile = useMediaQuery('(max-width: 768px)'); // In the JSX <NavLink to="/#" cn="mx-4 flex" setOpen={isMobile ? setOpen : undefined} > HOME </NavLink> // Repeat for other NavLinksThis would prevent unnecessary state updates on desktop views where the mobile navigation isn't used.
13-13
: Ensure router is defined before accessingWhile the static analysis tool flags a potential issue with
router.push(to)
, this is likely a false positive given the context. However, it's always good to add a safety check.Consider adding a null check before using the router:
if (router && typeof router.push === 'function') { router.push(to); } else { // Fallback behavior, e.g., using window.location window.location.href = to; }This will make the code more robust and prevent potential runtime errors if
router
is unexpectedly undefined.🧰 Tools
🪛 GitHub Check: CodeQL
[failure] 13-13: Property access on null or undefined
The base expression of this property access is always undefined.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- Website/app/Header.js (4 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeQL
Website/app/Header.js
[notice] 7-7: Unused variable, import, function or class
Unused import useRouter.
[failure] 13-13: Property access on null or undefined
The base expression of this property access is always undefined.
🔇 Additional comments (2)
Website/app/Header.js (2)
28-28
: LGTM: MobileNav prop updateThe addition of the
setOpen
prop to theMobileNav
component is a good change. It allows the component to control the mobile navigation state, which is consistent with the modifications made to theNavLink
component.
50-50
: LGTM: NavLink updates in MobileNavThe addition of the
setOpen
prop to theNavLink
components withinMobileNav
is correct and consistent with the earlier changes. This modification ensures that the mobile navigation closes when a link is clicked, improving the user experience.Also applies to: 57-57, 64-64
gosh.. what's going on lol |
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.
conversations are still there
@SaptarshiSarkar12 FINALLY fixed it! |
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.
@drippypop The fix no longer works 😞. Please check and make the necessary changes. Probably router doesn't work as expected.
@drippypop As the recent fixes don't work as expected, you can revert to commit d9a158a |
@SaptarshiSarkar12 sorry about that! I'll make sure to revert to that |
@drippypop Great 😃👍 |
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.
@drippypop Looks good to merge 👍.
Thanks for contributing 🚀 🚀.
You may join our Discord server - https://discord.gg/DeT4jXPfkG to get updates about the project.
Description:
This PR addresses the hydration error caused by text content mismatch in the server-rendered HTML in the
Header.js
file. The issue was due to nested<button>
elements. The following changes have been made to resolve this error:<button>
elements inside theNavLink
component.NavLink
component to use theLink
component properly.setOpen
function is called appropriately to handle toggling the mobile navigation.Changes:
Header.js
to remove nested<button>
elements.NavLink
component.File(s) Modified:
Website/app/Header.js
Before:
After:
Testing:
Issue Fixed:
Reviewer:
Summary by CodeRabbit
New Features
Bug Fixes