Quick story about a bug I shipped without knowing for weeks.
Ahrefs flagged a warning: "More than one page for same language in hreflang — 161 pages affected." I went to view source on a tool page and counted the hreflang tags.
52.
Should have been 26.
What was happening
My build process correctly generated 26 hreflang tags per page — 25 languages plus x-default. Clean.
But then at runtime, JavaScript was doing this:
function injectHreflang(slug) {
langs.forEach(lang => {
const link = document.createElement('link')
link.rel = 'alternate'
link.hreflang = lang
link.href = buildUrl(slug, lang)
document.head.appendChild(link)
})
}
appendChild. Not replace. Not "check if exists first." Just append, every time.
So every page shipped with 26 build-time tags in the static HTML, and then JS added 26 more on page load. Net result: 52 tags, every language listed twice pointing to identical URLs.
Why it mattered
Google's rule on duplicate hreflang: when a language appears twice with different URLs, it ignores both. When it appears twice with the same URL, Google still flags it as a signal-quality issue and downgrades trust in your hreflang setup overall.
I'd been wondering for weeks why non-English variants weren't ranking. Turns out I was telling Google "the French version is here AND also here" on 1,400+ pages.
The fix
I deleted the runtime injectHreflang() function entirely. Forty-one tool files were calling it — I removed the calls and the import everywhere.
The build-time tags were already correct. The runtime injection was redundant code from an earlier phase of the project that had outlived its purpose.
# Before
$ curl https://relahconvert.com/merge-pdf | grep hreflang | wc -l
52
# After
$ curl https://relahconvert.com/merge-pdf | grep hreflang | wc -l
26
The lesson
When something works at build time AND at runtime, it doesn't mean it's working twice as well. It usually means you have two systems fighting each other, and you'll only notice when an audit tool flags it.
You can see the fix in action on the RelahConvert PDF merger — view-source and count the hreflang tags yourself.
If you're building a multilingual site, check this on your own pages. Takes 10 seconds and the bug is more common than you'd think.
Top comments (0)