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

Fixed broken active link in developer docs navbar [Fixes #10813] #13331

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

0x0OZ
Copy link
Contributor

@0x0OZ 0x0OZ commented Jul 5, 2024

Description

There was an issue checking isHrefActive in Link.tsx because of the unremoved hashtags from the URL.

I don't know if that's the best way to deal with it or if this fix breaks assumptions on other components that assume hashtags remain in that check.

I am not really a good developer, so it will be great if someone double checks (patch source)

Related Issue

Fixes #10813

Copy link

netlify bot commented Jul 5, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 712d3b1
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/668911e4e1b79f0008ecb490
😎 Deploy Preview https://deploy-preview-13331--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 47 (🔴 down 4 from production)
Accessibility: 92 (no change from production)
Best Practices: 91 (🔴 down 1 from production)
SEO: 93 (no change from production)
PWA: -
View the detailed breakdown and full score reports

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

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.

Thanks @0x0OZ! Appreciate you dropping this.

Taking a look here, I think we should probably patch the isHrefActive function instead, to do this same logic.

My thought here is, that function should answer "is this href active?", which should always be ignoring the hash links (anything after a #) or any query/search params (anything after a ?). We shouldn't have to pre-sanitize our pathname when passing to this function in my opinion.

const cleanAsPath = asPath.replace(/#.*/, "");

If you look inside src/lib/utils/url.ts (where you're importing isHrefActive, you'll see another helper function called cleanPath:

// remove any query params or hashes from the path
export const cleanPath = (path: string): string => path.replace(/[$#].+$/, "")

This is very similar to the logic you added, but will also remove any query/search params as well. Let's use this instead.

I would recommend the following:

  1. Revert these changes to Link.tsx
  2. Update the isHrefActive function inside url.ts: Instead of pathname === href, let's wrap pathname with cleanPath, ie: cleanPath(pathname) === href
  3. We're using cleanPath inside isHrefActive so let's move the cleanPath function above the other so we're not using functions before they're declared. This isn't strictly necessary due to JS hoisting but is good practice.
  4. Make sure we run the linter on this to keep it tidy: yarn prettier --write src/lib/utils/url.ts
  5. Run yarn dev and test it out in the browser to make sure this is working as expected

Hope that helps!

@github-actions github-actions bot added the tooling 🔧 Changes related to tooling of the project label Jul 6, 2024
@0x0OZ 0x0OZ requested a review from wackerow July 6, 2024 11:22
@0x0OZ
Copy link
Contributor Author

0x0OZ commented Jul 6, 2024

I think this looks good

Copy link
Contributor

github-actions bot commented Aug 6, 2024

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Status: Stale This issue is stale because it has been open 30 days with no activity. label Aug 6, 2024
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.

🎉 Beautiful! Sorry for delay, looks great @0x0OZ! Bringing in

@wackerow wackerow merged commit 98d8b2d into ethereum:dev Aug 27, 2024
6 checks passed
This was referenced Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale This issue is stale because it has been open 30 days with no activity. tooling 🔧 Changes related to tooling of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug report: Fix marker in the developer docs sidebar of the current active page
2 participants