Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 5 min read

How I Built a Pre-Merge SSR SEO Audit Gate for Next.js 16 Content Pages

When you ship programmatic or template-driven content pages in Next.js, next build and ESLint will happily pass while your pages quietly fail in Google Search Console as "Crawled - currently not indexed." I ran into thi

When you ship programmatic or template-driven content pages in Next.js, next build and ESLint will happily pass while your pages quietly fail in Google Search Console as "Crawled - currently not indexed."

I ran into this firsthand while building and scaling structured reference pages for Tarot Fortune Cards on Next.js 16 (App Router) + React 19 + next-intl. The UI looked great in Chrome, Lighthouse was green, and every route compiled cleanlyβ€”yet inspecting the raw HTML that crawlers actually receive exposed four subtle bugs that were silently hurting indexation.

Instead of doing manual spot-checks after deployment, I turned those failure modes into an automated two-stage pre-merge SEO gate (static repo check + live Vercel preview SSR HTML check). Here is what it catches and the exact patterns you can drop into your own Next.js workflow.

Why Checking in Chrome DevTools Lies

Modern Next.js apps mix Server Components, Client Components, dynamic imports, and next/image. When you inspect a page in Chrome DevTools, you are looking at the post-hydration DOM.

Search crawlers do render JavaScript eventually, but initial crawl discovery, canonical evaluation, and structured data extraction still heavily favor clean first-response SSR HTML. If your primary content, comparison tables, or FAQ answers only appear after client hydrationβ€”or if your template accidentally repeats 30% of the same sentences across sibling routesβ€”indexation slows down dramatically.

The 4 Silent Bugs Our Pre-Merge Gate Catches

1. Cross-Page Boilerplate Overlap (Template Cannibalization)

Even when every page is hand-written or carefully edited, shared intros, transition paragraphs, disclaimers, and CTA blocks add up fast. Across a cluster of sibling reference pages, it is surprisingly easy to end up with 25–40% identical sentences, which looks like thin templated content to search engines.

Our static audit extracts visible prose from every page in a batch and enforces a hard < 15% pairwise normalized sentence overlap ceiling before a branch is allowed to merge:

import re
from itertools import combinations

def normalize_sentences(text: str) -> set[str]:
    # Split on sentence boundaries and ignore very short UI labels (< 6 words)
    raw = re.split(r"(?<=[.!?])\s+", text)
    sentences = set()
    for s in raw:
        cleaned = re.sub(r"[^a-z0-9\s]", "", s.lower()).strip()
        if len(cleaned.split()) >= 6:
            sentences.add(cleaned)
    return sentences

def pairwise_overlap(pages: dict[str, str], threshold: float = 0.15) -> list[tuple]:
    failures = []
    sets = {slug: normalize_sentences(txt) for slug, txt in pages.items()}
    for a, b in combinations(sets.keys(), 2):
        union = sets[a] | sets[b]
        if not union:
            continue
        jaccard = len(sets[a] & sets[b]) / len(union)
        if jaccard >= threshold:
            failures.append((a, b, round(jaccard * 100, 1)))
    return failures

Running this before merge caught duplicate framing sentences in our first draft batch immediatelyβ€”forcing us to rewrite shared section leads into page-specific explanations and cutting overlap down to under 5%.

2. Above-the-Fold Media Accidentally Lazy-Loaded or Oversized

Template pages often share a single hero or visual component. One careless loading="lazy" attribute (or leaving an unoptimized 300 KB+ PNG in /public) will silently push mobile LCP past 3 seconds across every route using that template.

Our pre-merge rule for primary visual assets:

  • Convert every primary visual to WebP and enforce a hard <= 60 KB file-size cap in the static repo check.
  • Require explicit width and height attributes on the rendered <img> tag to eliminate CLS.
  • Assert on the raw SSR HTML that the above-the-fold visual does not contain loading="lazy".

3. Broken Heading Hierarchy & Missing Server-Rendered Structured Data

In Next.js App Router, we keep route files thin and pull typed metadata and structured content from a central config module:

import { setRequestLocale } from 'next-intl/server';
import { TarotSeoLandingPage } from '@/shared/blocks/tarot/seo-landing-page';
import {
  createTarotSeoMetadata,
  getTarotSeoPage,
} from '@/shared/lib/tarot-seo-pages';

export const generateMetadata = createTarotSeoMetadata(
  'king-of-swords-yes-or-no'
);

export default async function KingOfSwordsYesOrNoPage({
  params,
}: {
  params: Promise<{ locale: string }>;
}) {
  const { locale } = await params;
  setRequestLocale(locale);

  return (
    <TarotSeoLandingPage page={getTarotSeoPage('king-of-swords-yes-or-no')} />
  );
}

Then, against the deployed Vercel Preview URL (before merging to main), the second stage of our script fetches the raw HTML directlyβ€”no headless browserβ€”and validates:

  1. HTTP 200 + canonical matches the exact production slug URL.
  2. Title length (30–60 chars) and meta description (120–160 chars), with sitewide uniqueness so two routes never accidentally share the same <title>.
  3. Exactly one <h1>, and zero skipped heading levels (h1 -> h2 -> h3, never jumping straight from h1 to h4).
  4. Core content in raw HTML: minimum word count threshold, semantic HTML <table> for quick-scan facts, and FAQ questions rendered inside real heading tags (<h3>) rather than collapsed client-only accordions that vanish when JS is disabled.
  5. Valid JSON-LD: parses every <script type="application/ld+json"> block and verifies both BreadcrumbList and FAQPage parse cleanly as valid JSON with non-empty items.
  6. sitemap.xml & robots.txt check: confirms the new slug is actually included in sitemap.xml and not accidentally blocked by noindex or Disallow.

If you want to see what the passing raw SSR output looks like in practice, run view-source: on our King of Swords Yes or No guideβ€”every heading, quick-reference table, FAQ answer, < 60 KB eager WebP asset, and JSON-LD block is present in the initial server response before React hydrates.

4. Accidental Regression on Existing Top-Ranking Pages

This is the one most developers forget until traffic drops.

When you refactor a shared layout or metadata helper to support new content pages, it is dangerously easy to alter the <title>, meta description, or <h1> of your existing top-performing URLs.

Our static audit keeps a short list of protected slugs (our top organic landing pages) and diffs their resolved title, description, and h1 against origin/main before every PR merge. If a refactor touches any protected page's TDH unexpectedly, the check fails immediately with FAIL > 0 and blocks the merge.

The Two-Stage Checklist Summary

Stage Target What It Blocks
1. Static Repo Gate Git branch before push Duplicate titles/descriptions, pairwise sentence overlap >= 15%, local WebP > 60 KB, missing inbound links, mutations to protected top-ranking pages
2. Live Preview SSR Gate Raw HTML from Vercel Preview Non-200 status, wrong canonical, noindex leaks, multiple <h1>s, loading="lazy" on hero images, invalid JSON-LD, missing sitemap.xml entry

Running both stages takes under 5 seconds locally and eliminates an entire class of "why didn't Google index my new Next.js pages?" debugging two weeks later.

What pre-merge checks do you run on your Next.js or programmatic SEO templates before pushing to production?

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.