Skip to content

Commit fb12efb

Browse files
committed
feat: enhance SERP title overflow checks for desktop and mobile views
1 parent 7f6a94d commit fb12efb

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

packages/devtools-seo/src/tabs/serp-preview.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type SerpData = {
2525
}
2626

2727
type SerpOverflow = {
28-
titleOverflow: boolean
28+
titleOverflowDesktop: boolean
29+
titleOverflowMobile: boolean
2930
descriptionOverflow: boolean
3031
descriptionOverflowMobile: boolean
3132
}
@@ -64,8 +65,8 @@ const COMMON_CHECKS: Array<SerpCheck> = [
6465
},
6566
{
6667
message:
67-
'The title is wider than 600px and it may not be displayed in full length.',
68-
hasIssue: (_, overflow) => overflow.titleOverflow,
68+
`The title is wider than ${DESKTOP_TITLE_MAX_WIDTH_PX}px and it may not be displayed in full length.`,
69+
hasIssue: (_, overflow) => overflow.titleOverflowDesktop,
6970
},
7071
]
7172

@@ -85,6 +86,10 @@ const SERP_PREVIEWS: Array<SerpPreview> = [
8586
label: 'Mobile preview',
8687
isMobile: true,
8788
extraChecks: [
89+
{
90+
message: `The title is wider than ${MOBILE_TITLE_MAX_WIDTH_PX}px and may be trimmed in the mobile preview.`,
91+
hasIssue: (_, overflow) => overflow.titleOverflowMobile,
92+
},
8893
{
8994
message:
9095
'Description exceeds the 3-line limit for mobile view. Please shorten your text to fit within 3 lines.',
@@ -326,8 +331,10 @@ function getSerpPreviewState(data: SerpData): SerpPreviewState {
326331
DESCRIPTION_FONT,
327332
),
328333
overflow: {
329-
titleOverflow:
334+
titleOverflowDesktop:
330335
measureTextWidth(titleText, TITLE_FONT) > DESKTOP_TITLE_MAX_WIDTH_PX,
336+
titleOverflowMobile:
337+
measureTextWidth(titleText, TITLE_FONT) > MOBILE_TITLE_MAX_WIDTH_PX,
331338
descriptionOverflow:
332339
desktopDescriptionLines.length > DESKTOP_DESCRIPTION_MAX_LINES ||
333340
desktopDescriptionLines.reduce(
@@ -404,11 +411,17 @@ export function getSerpPreviewSummary(): SeoSectionSummary {
404411
message: 'No meta description set on the page.',
405412
})
406413
}
407-
if (overflow.titleOverflow) {
414+
if (overflow.titleOverflowDesktop) {
408415
issues.push({
409416
severity: 'warning',
410417
message:
411-
'The title is wider than 600px and it may not be displayed in full length.',
418+
`The title is wider than ${DESKTOP_TITLE_MAX_WIDTH_PX}px and it may not be displayed in full length.`,
419+
})
420+
}
421+
if (overflow.titleOverflowMobile) {
422+
issues.push({
423+
severity: 'warning',
424+
message: `The title is wider than ${MOBILE_TITLE_MAX_WIDTH_PX}px and may be trimmed in the mobile preview.`,
412425
})
413426
}
414427
if (overflow.descriptionOverflow) {

packages/devtools-seo/src/utils/tokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ export const tokens = {
271271
96: 'calc(var(--tsrd-font-size) * 24)',
272272
},
273273
shadow: {
274-
xs: (_: string = 'rgb(0 0 0 / 0.1)') =>
275-
`0 1px 2px 0 rgb(0 0 0 / 0.05)` as const,
274+
xs: (color: string = 'rgb(0 0 0 / 0.05)') =>
275+
`0 1px 2px 0 ${color}` as const,
276276
sm: (color: string = 'rgb(0 0 0 / 0.1)') =>
277277
`0 1px 3px 0 ${color}, 0 1px 2px -1px ${color}` as const,
278278
md: (color: string = 'rgb(0 0 0 / 0.1)') =>

0 commit comments

Comments
 (0)