diff --git a/packages/docs-config/src/analytics.ts b/packages/docs-config/src/analytics.ts index 9e52fa46..61e1efd1 100644 --- a/packages/docs-config/src/analytics.ts +++ b/packages/docs-config/src/analytics.ts @@ -62,6 +62,9 @@ export const ANALYTICS_SCRIPT_ORIGINS: readonly string[] = [ "https://static.hotjar.com", // Hotjar's surveys (survey-v2.*.js), measured on coder.com/docs on 2026-11-30. "https://script.hj.contentsquare.net", + // Reo's third-party tracking: the Sitelytics pixel and the Sovrn pixel it loads, measured on coder.com/docs on 2026-12-04. + "https://cdn.sitelytics.tech", + "https://pxdrop.lijit.com", ]; /** diff --git a/packages/docs-next/src/docs-link.test.tsx b/packages/docs-next/src/docs-link.test.tsx new file mode 100644 index 00000000..50008ac3 --- /dev/null +++ b/packages/docs-next/src/docs-link.test.tsx @@ -0,0 +1,37 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import type { ComponentProps } from "react"; +import { renderToFragment } from "../test/dom.js"; +import { withPlainAbsoluteLinks } from "./docs-link.js"; + +function AppLink({ href, children, ...props }: ComponentProps<"a">) { + return ( + + {children} + + ); +} +const DocsLink = withPlainAbsoluteLinks(AppLink); + +test("a full URL is a plain anchor, so the docs app never prefetches or routes it", () => { + for (const href of ["https://coder.com/", "https://coder.com/pricing", "//coder.com/"]) { + const link = renderToFragment( + + home + , + ).querySelector("a"); + assert.equal(link?.hasAttribute("data-app-link"), false, href); + assert.equal(link?.getAttribute("href"), href); + assert.equal(link?.getAttribute("aria-label"), "Coder home"); + assert.equal(link?.getAttribute("class"), "mark"); + assert.equal(link?.textContent, "home"); + } +}); + +test("a path in the docs keeps the app's link", () => { + for (const href of ["/", "/install", "#top"]) { + const link = renderToFragment(page).querySelector("a"); + assert.equal(link?.hasAttribute("data-app-link"), true, href); + assert.equal(link?.getAttribute("href"), href); + } +}); diff --git a/packages/docs-next/src/docs-link.tsx b/packages/docs-next/src/docs-link.tsx new file mode 100644 index 00000000..be10385a --- /dev/null +++ b/packages/docs-next/src/docs-link.tsx @@ -0,0 +1,26 @@ +"use client"; +import NextLink from "next/link"; +import type { ComponentProps, FC } from "react"; + +type LinkProps = ComponentProps<"a"> & { prefetch?: boolean }; + +/** Fumadocs' framework link, with full URLs left to the browser: Next would treat a same-origin one as a docs page and prefetch it. */ +export function withPlainAbsoluteLinks(AppLink: FC): FC { + return function DocsLink({ href, prefetch, children, ...props }: LinkProps) { + if (href !== undefined && (/^\w+:/.test(href) || href.startsWith("//"))) + return ( + + {children} + + ); + return ( + + {children} + + ); + }; +} + +export const DocsLink = withPlainAbsoluteLinks(({ href = "#", ...props }) => ( + +)); diff --git a/packages/docs-next/src/provider.test.tsx b/packages/docs-next/src/provider.test.tsx index 6bfac846..c2435b4e 100644 --- a/packages/docs-next/src/provider.test.tsx +++ b/packages/docs-next/src/provider.test.tsx @@ -5,6 +5,7 @@ import type { RootProvider } from "fumadocs-ui/provider/next"; import type { ComponentProps } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { renderToFragment } from "../test/dom.js"; +import { DocsLink } from "./docs-link.js"; import { DocsProvider } from "./provider.js"; // A stand-in for the fumadocs RootProvider that records the props it receives @@ -152,6 +153,16 @@ test("options.provider replaces the default fumadocs RootProvider", () => { assert.equal(out.querySelector("[data-stub-provider='true']")?.textContent, "content"); }); +test("fumadocs' links render through the docs link, so a full URL stays a plain anchor", () => { + captured.props = undefined; + renderToStaticMarkup( + + + , + ); + assert.equal(getCaptured()?.components?.Link, DocsLink); +}); + test("options.search.hybrid swaps in the hybrid search dialog", () => { renderToStaticMarkup( diff --git a/packages/docs-next/src/provider.tsx b/packages/docs-next/src/provider.tsx index 0c6b55c3..4658da3a 100644 --- a/packages/docs-next/src/provider.tsx +++ b/packages/docs-next/src/provider.tsx @@ -8,6 +8,7 @@ import type { SearchProviderProps } from "fumadocs-ui/contexts/search"; import { RootProvider } from "fumadocs-ui/provider/next"; import type { ComponentProps, ComponentType, ReactNode } from "react"; import { lazy } from "react"; +import { DocsLink } from "./docs-link.js"; // Its own chunk, so a provider without `hybrid` never downloads it. const HybridSearchDialog = lazy(() => import("./hybrid-search.js")); @@ -106,6 +107,7 @@ export function DocsProvider({ const Provider = options?.provider ?? RootProvider; const providerProps: FumadocsRootProviderProps = { search: buildSearchProp(options?.search), + components: { Link: DocsLink }, ...(options?.theme !== undefined ? { theme: options.theme } : {}), }; return (