Skip to content

Commit 566271b

Browse files
committed
refactor(devtools): simplify link classification logic in links preview component
This commit refactors the classifyLink function in the links preview component by removing unnecessary checks for non-web links and the 'nofollow' issue reporting. It enhances the handling of relative paths and same-document fragments to align with browser behavior, improving code clarity and maintainability in the SEO tab.
1 parent ea5e33c commit 566271b

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

packages/devtools/src/tabs/seo-tab/links-preview.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ function classifyLink(anchor: HTMLAnchorElement): LinkRow {
4141
return { text, href, resolvedHref: null, kind: 'invalid', issues }
4242
}
4343

44-
if (href.startsWith('#')) {
45-
return { text, href, resolvedHref: null, kind: 'non-web', issues }
46-
}
47-
44+
// Resolve relative paths and same-document fragments (#section) against the
45+
// current document, matching browser behavior so framework-generated hrefs
46+
// (paths without origin) and hash links classify as internal when same-origin.
4847
let resolved: URL | null = null
4948
try {
5049
resolved = new URL(href, window.location.href)
@@ -84,12 +83,6 @@ function classifyLink(anchor: HTMLAnchorElement): LinkRow {
8483
message: 'External _blank link should include rel="noopener".',
8584
})
8685
}
87-
if (!relTokens.includes('nofollow')) {
88-
issues.push({
89-
severity: 'info',
90-
message: 'External link does not include nofollow.',
91-
})
92-
}
9386
}
9487

9588
return {

0 commit comments

Comments
 (0)