Skip to content

fix(seo-head): build URLs from config.url, not $page.url.origin#9

Open
jaysin586 wants to merge 1 commit into
mainfrom
fix/seohead-config-origin
Open

fix(seo-head): build URLs from config.url, not $page.url.origin#9
jaysin586 wants to merge 1 commit into
mainfrom
fix/seohead-config-origin

Conversation

@jaysin586
Copy link
Copy Markdown
Contributor

Problem

Every consumer of docs-kit ships <meta property="og:image"> URLs that leak SvelteKit's internal prerender hostname into the production HTML:

<meta property="og:image" content="http://sveltekit-prerender/social-cards/og-compare-vs-marked.png"/>

That http://sveltekit-prerender is the sentinel origin SvelteKit uses during prerender. It rewrites this placeholder in <link href> attributes and similar href-like contexts — but not inside <meta content="..."> values. So og:image and twitter:image carry the placeholder into the static HTML, and every social previewer (Twitter/X, LinkedIn, Slack, Discord, Facebook…) sees a connection-level failure (HTTP 000) trying to fetch from a hostname that doesn't resolve.

Canonical and og:url happen to render with the right origin today only because SvelteKit post-processes <link href> attrs. Brittle.

Fix

SeoHead.svelte now builds URLs from config.url (already required in DocsKitConfig) rather than $page.url.origin. A siteOrigin derived strips a trailing slash defensively so consumers can pass url with or without one.

The four affected emissions are now stable across SSR, prerender, and runtime:

  • <link rel="canonical">
  • <meta property="og:url">
  • <meta property="og:image">
  • <meta name="twitter:image">

Verification

Reproduced on markdown.svelte.page (all 10 /compare/vs-* pages):

Before After (expected)
og:image host http://sveltekit-prerender https://markdown.svelte.page
Image fetch HTTP 000 (DNS fail) HTTP 200 (~235 KB PNG)

The PNGs themselves already exist at the correct paths in static/social-cards/ — this is purely a URL-resolution bug. Once each consumer repo bumps docs-kit and rebuilds, their social previews start working.

Scope of consumer impact

Every consumer of @humanspeak/docs-kit inherits the fix on next pin bump — svelte-markdown, svelte-motion, svelte-headless-table, svelte-virtual-list, svelte-virtual-chat, svelte-json-view-lite, memory-cache, svelte-purify, svelte-diff-match-patch, svelte-page. No app code changes required — only a dependency pin update.

Notes on the diff

Prettier also reformatted some pre-existing nested-ternary indentation on the same file (resolvedTitle, resolvedDescription). Those changes are semantically identical — only style. File now passes prettier --check and svelte-check cleanly.

🤖 Generated with Claude Code

During SvelteKit prerender, `$page.url.origin` resolves to the sentinel
`http://sveltekit-prerender`. SvelteKit rewrites this placeholder in
`<link href>` attributes but NOT inside `<meta content="...">` — so
og:image and twitter:image have been leaking the placeholder origin into
production HTML, breaking Twitter/X, LinkedIn, Slack, Discord, and
Facebook social previews. Canonical and og:url happen to render correctly
today purely because SvelteKit post-processes `<link href>` and href-like
attrs; relying on that is brittle.

Switch SeoHead to build canonical, og:image, og:url, and twitter:image
from `config.url` (already required in DocsKitConfig). A small
`siteOrigin` derived strips a trailing slash defensively so consumers can
configure `url` with or without one.

Verified on markdown.svelte.page: 10 `/compare/vs-*` pages currently emit
`http://sveltekit-prerender/social-cards/og-compare-vs-{slug}.png`. The
PNGs already exist at the correct path — this is purely a URL-resolution
bug. Once consumers bump docs-kit, the previews start working
immediately.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3f60fed-3ff5-421e-9a15-5a07b85dbaf7

📥 Commits

Reviewing files that changed from the base of the PR and between 8d0a50f and 1f5ad1f.

📒 Files selected for processing (1)
  • src/lib/components/SeoHead.svelte

📝 Walkthrough

Walkthrough

SeoHead component updates SEO URL generation to use site configuration instead of page origin. A new siteOrigin value derives from config.url with trailing slashes removed, then feeds into canonicalUrl and ogImageUrl computations. Title and description metadata logic remains functionally identical.

Changes

SEO URL Derivation from Site Configuration

Layer / File(s) Summary
SEO URL computation from site configuration
src/lib/components/SeoHead.svelte
siteOrigin is derived from config.url with trailing slashes trimmed. canonicalUrl and ogImageUrl now use siteOrigin instead of $page.url.origin. resolvedTitle and resolvedDescription are reformatted but preserve the same seo-override-first precedence logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through config URLs with glee,
Trading page origins for consistency,
Trailing slashes trimmed with careful care,
SEO metadata now rooted in the lair,
Canonical paths spring fresh and fair! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(seo-head): build URLs from config.url, not $page.url.origin' accurately and concisely summarizes the main change: replacing $page.url.origin with config.url for building SEO-related URLs in SeoHead.svelte.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the problem (SEO URLs leaking SvelteKit's prerender sentinel origin), the fix (using config.url instead), and verification steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/seohead-config-origin

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant