Skip to content

Commit 25ec4d7

Browse files
committed
refactor(devtools): enhance SEO tab components by removing canonical link and improving robots handling
This commit removes the canonical link from the basic example HTML file and updates the robots handling logic in the canonical URL data module. The changes include refining the conditions for indexability and follow directives, ensuring more accurate SEO assessments. Additionally, the links preview component is updated to enforce the inclusion of both 'noopener' and 'noreferrer' for external links with target='_blank'. These adjustments aim to improve the overall functionality and security of the SEO tab.
1 parent a2bb1a3 commit 25ec4d7

File tree

5 files changed

+17
-200
lines changed

5 files changed

+17
-200
lines changed

examples/react/basic/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
content="A basic example of using TanStack Devtools with React."
3434
/>
3535

36-
<link rel="canonical" href="http://localhost:3005/" />
37-
3836
<meta name="robots" content="index, follow" />
3937

4038
<description

packages/devtools/src/tabs/seo-tab/README.md

Lines changed: 0 additions & 190 deletions
This file was deleted.

packages/devtools/src/tabs/seo-tab/canonical-url-data.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ export function getCanonicalPageData(): CanonicalPageData {
8888
.filter(Boolean),
8989
)
9090

91-
const indexable = !robots.includes('noindex')
92-
const follow = !robots.includes('nofollow')
91+
const hasNoindex = robots.includes('noindex') || robots.includes('none')
92+
const hasNofollow = robots.includes('nofollow') || robots.includes('none')
93+
const indexable = !hasNoindex
94+
const follow = !hasNofollow
9395

9496
if (!indexable) {
9597
issues.push({ severity: 'error', message: 'Page is marked as noindex.' })

packages/devtools/src/tabs/seo-tab/json-ld-preview.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,20 @@ function hasMissingKeys(
124124
})
125125
}
126126

127+
const VALID_SCHEMA_CONTEXTS = new Set([
128+
'https://schema.org',
129+
'http://schema.org',
130+
'https://schema.org/',
131+
'http://schema.org/',
132+
])
133+
127134
function validateContext(entity: JsonLdValue): Array<ValidationIssue> {
128135
const context = entity['@context']
129136
if (!context) {
130137
return [{ severity: 'error', message: 'Missing @context attribute.' }]
131138
}
132139
if (typeof context === 'string') {
133-
if (
134-
!context.includes('schema.org') &&
135-
context !== 'https://schema.org' &&
136-
context !== 'http://schema.org'
137-
) {
140+
if (!VALID_SCHEMA_CONTEXTS.has(context)) {
138141
return [
139142
{
140143
severity: 'error',

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ function classifyLink(anchor: HTMLAnchorElement): LinkRow {
7777
.split(/\s+/)
7878
.filter(Boolean)
7979

80-
if (target === '_blank' && !relTokens.includes('noopener')) {
80+
if (
81+
target === '_blank' &&
82+
!relTokens.includes('noopener') &&
83+
!relTokens.includes('noreferrer')
84+
) {
8185
issues.push({
8286
severity: 'warning',
8387
message: 'External _blank link should include rel="noopener".',

0 commit comments

Comments
 (0)