fix(blog): strip query string and hash from SEO canonical and JSON-LD URLs - #1645
Conversation
… URLs Requests arriving with ?utm_source=..., ?page=2 or a #hash were leaking those into the canonical link, the BlogPosting/Blog url and mainEntityOfPage, and the BreadcrumbList items emitted by SeoBlogPost and SeoBlogPostListing. Normalize in withCanonicalBase so every emitted URL is origin + pathname only, both with and without a configured canonicalBaseUrl. Relative URLs without a base still pass through unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 21 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Tagging OptionsShould a new tag be published when this PR is merged?
|
Problem
The blog SEO sections (
blog/sections/Seo/SeoBlogPost.tsxandblog/sections/Seo/SeoBlogPostListing.tsx) build the page URL used for the<link rel="canonical">, theurl/mainEntityOfPageof theBlogPosting/BlogJSON-LD nodes, and theBreadcrumbListitems. A request arriving with?utm_source=x,?page=2or a#hashleaked those into every emitted URL, producing dirty canonicals and JSON-LD URLs that vary between requests for the same page.This happened in both paths: with
canonicalBaseUrlconfigured (withCanonicalBasepreservedsearch + hash) and without it (the request URL passed through untouched).Fix
Normalize in
withCanonicalBase(blog/utils/jsonLD.ts), which every emitted URL flows through: keep only origin + pathname, dropping query string and hash in both paths.Preserved behavior:
req.urlin the sections (no exceptions thrown);URL.canParse);Validation
deno check,deno fmt --checkanddeno lintpass on the helper and both sections (pre-commit hook also ran the repo-wide check).deno evalassertions covering:https://loja.com/blog/post?page=2#top→https://loja.com/blog/post(no base)https://loja.com/blog/post?page=2#top+ basehttps://www.loja.com.br→https://www.loja.com.br/blog/post/blog/dicasresolved against areq.urlcarrying?utm_source=x, with and without base🤖 Generated with Claude Code
Summary by cubic
Strip query strings and hashes from blog SEO URLs so canonicals and JSON-LD stay clean and consistent across requests. Fixes noise from UTM params, pagination, and hash fragments.
withCanonicalBaseto origin + pathname; works with or without a base.<link rel="canonical">, JSON-LDurl/mainEntityOfPage, andBreadcrumbList; relative URLs without a base pass through unchanged.Written for commit 42a1476. Summary will update on new commits.