fix: preserve search params in canonical URL on stateful routes#864
fix: preserve search params in canonical URL on stateful routes#864tannerlinsley merged 2 commits intomainfrom
Conversation
The npm stats pages encode their entire UI state (selected packages, range, transform, etc.) in search params, but __root.tsx built the canonical link, og:url, and twitter:url from pathname only. iOS Share read those tags and shared a bare /stats/npm URL, dropping the comparison the user had configured. Routes can now opt in via staticData.includeSearchInCanonical; when set, the current searchStr is appended to the canonical URL. Applied to /stats/npm/, /stats/npm/$packages, and the per-library /$libraryId/$version/docs/npm-stats route.
Extends the includeSearchInCanonical opt-in to additional routes whose UI state lives in search params, so iOS Share and other clients that read the canonical/og:url/twitter:url tags share the user's configured view rather than a default one. - /builder (entire builder config: framework, features, tab, file…) - /maintainers (libraries, viewMode, groupBy, sortBy) - /partners (libraries, status) - /intent/registry (q, tab, framework, sort, view) - /shop, /shop/search, /shop/collections/$handle
✅ Deploy Preview for tanstack ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThis change implements optional search parameter inclusion in canonical URLs across the application. It adds a new Changes
Sequence DiagramsequenceDiagram
participant Router as TanStack Router
participant ShellComp as Root Shell Component
participant SEOUtil as canonicalUrl Utility
Router->>ShellComp: Render with matched route & search params
ShellComp->>ShellComp: Capture location.searchStr
ShellComp->>ShellComp: Check route.staticData.includeSearchInCanonical
alt includeSearchInCanonical is true
ShellComp->>SEOUtil: canonicalUrl(path, searchStr)
else includeSearchInCanonical is false/undefined
ShellComp->>SEOUtil: canonicalUrl(path, '')
end
SEOUtil->>SEOUtil: Normalize path and search
SEOUtil->>ShellComp: Return full canonical URL
ShellComp->>ShellComp: Set <link rel="canonical"> href
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |

Summary
The npm stats pages (and several other tools/dashboards) encode their entire UI state in URL search params, but
__root.tsxbuilt the canonical link,og:url, andtwitter:urlfrompathnameonly. iOS Share read those tags and shared a bare URL, dropping the user's configured view (e.g. selected packages, range, filters).canonicalUrl(path, search?)now optionally appends a search string (src/utils/seo.ts).__root.tsxreadslocation.searchStrand usesuseMatchesto check forstaticData.includeSearchInCanonical === true; when set, the search string is threaded through the canonical link,og:url, andtwitter:url.StaticDataRouteOptioninsrc/router.tsxaugmented withincludeSearchInCanonical?: boolean./stats/npm/,/stats/npm/$packages,/$libraryId/$version/docs/npm-stats/builder/maintainers/partners/intent/registry/shop,/shop/search,/shop/collections/$handleRoutes whose only search params are incidental (pagination, UI prefs) are intentionally left as-is to keep their canonical URLs SEO-clean.
Test plan
/stats/npm, configure a non-default package comparison, view source — confirm<link rel="canonical">,og:url,twitter:urlall include the?packageGroups=…search params/builderwith a non-default config/— confirm canonical URL is unchanged (no spurious search params)/stats/npm?packageGroups=…now produces a URL that loads the same comparisonhttps://claude.ai/code/session_01VbTHG1oRfPsECJ8pcr3qj8
Generated by Claude Code
Summary by CodeRabbit
Release Notes