Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/docs-config/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];

/**
Expand Down
37 changes: 37 additions & 0 deletions packages/docs-next/src/docs-link.test.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<a {...props} href={href} data-app-link="">
{children}
</a>
);
}
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(
<DocsLink href={href} aria-label="Coder home" className="mark">
home
</DocsLink>,
).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(<DocsLink href={href}>page</DocsLink>).querySelector("a");
assert.equal(link?.hasAttribute("data-app-link"), true, href);
assert.equal(link?.getAttribute("href"), href);
}
});
26 changes: 26 additions & 0 deletions packages/docs-next/src/docs-link.tsx
Original file line number Diff line number Diff line change
@@ -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<LinkProps>): FC<LinkProps> {
return function DocsLink({ href, prefetch, children, ...props }: LinkProps) {
if (href !== undefined && (/^\w+:/.test(href) || href.startsWith("//")))
return (
<a {...props} href={href}>
{children}
</a>
);
return (
<AppLink {...props} href={href} prefetch={prefetch}>
{children}
</AppLink>
);
};
}

export const DocsLink = withPlainAbsoluteLinks(({ href = "#", ...props }) => (
<NextLink {...props} href={href} />
));
11 changes: 11 additions & 0 deletions packages/docs-next/src/provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
<DocsProvider options={{ provider: StubProvider }}>
<span />
</DocsProvider>,
);
assert.equal(getCaptured()?.components?.Link, DocsLink);
});

test("options.search.hybrid swaps in the hybrid search dialog", () => {
renderToStaticMarkup(
<DocsProvider options={{ provider: StubProvider, search: { hybrid: true } }}>
Expand Down
2 changes: 2 additions & 0 deletions packages/docs-next/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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 (
Expand Down
Loading