Page History

Workspace changes

Highlight uncommitted edits in the rendered page while you write.

While the development server runs, Page History can compare each page with its last commit and mark the differences in the rendered page itself, with no separate diff view. Removed text is red and struck through, and added text is green. Changed blocks also get a bar on the left edge, solid for added and dashed for removed, so you can tell them apart without relying on color. Try it in the demo.

Enable local comparison

Enable the compiler option

After installing the plugin, add workspaceChanges: true next to repository in its options:

{
  repository: { url: 'https://github.com/owner/repository' },
  workspaceChanges: true,
}

Add the local endpoint

The page fetches its comparison from an API route. In Next.js:

app/api/page-changes/route.ts
import { createWorkspaceHandler } from 'fumadocs-page-history/workspace';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
export const GET = createWorkspaceHandler({ contentDirectory: 'content/docs' });

contentDirectory is your content folder's path from the root of the Git repository, not from the app. If the app lives in a subfolder, include it: this site, for example, uses docs/content/docs. Set repositoryDirectory only if the server runs outside the checkout. To serve the route at another URL, set workspaceChanges: { endpoint: '/api/my-page-changes' }.

Review changes

Open any page. It is compared with the last commit, so both staged and unstaged edits show up.

You changeWhat you see
A few words in a paragraphThe paragraph appears once, with removed words in red and new words in green.
Most of a paragraphThe old and new paragraphs both appear in full, with changed words highlighted.
A link's URLThe link text is highlighted. Hover it to see the old and new URLs.
A tableA new row is highlighted on its own. A replaced table appears as old and new.
A whole blockThe added or removed block is highlighted, with a bar on its left edge.
FrontmatterA notice says that the page metadata, such as the title, changed.
The file nameThe file is compared under its old name. Unchanged text isn't highlighted.

A new file shows up as entirely added. Commit or discard your edits, and the highlights disappear.

Automatic updates

Saving a file updates the page as usual. Staging, committing, and reverting are picked up within three seconds, or as soon as you switch back to the window, without a restart. If a request fails, the page keeps retrying.

While the development server rebuilds, highlights wait until the page shows your latest save, so they never land on outdated text.

The contributors and history sections work differently: they're saved into the page when it compiles, so they update only after a restart. See Troubleshooting.

Scope and limits

Comparison only runs in development. Production builds contain no highlighting code, and the endpoint returns 404. In development, the endpoint answers only same-origin requests from localhost and reads only Markdown and MDX files inside contentDirectory. It never changes anything in Git.

  • Paragraphs: text, inline code, links, and emphasis are compared word by word. Word boundaries work for Chinese too.
  • Lists: items are compared one by one, so unchanged items appear once. Simple items get word highlights. An item with a nested list or several paragraphs is shown as its old and new versions. Numbering and task checkboxes are kept.
  • Other content: code blocks, MDX components, and replaced tables are shown as whole old and new blocks. Removed content is rendered as plain Markdown, so a removed custom component may not look like the original.
  • Not compared: binary files, files with merge conflicts, very complex changes, and files over 200,000 bytes. The page shows a notice instead. To change the size limit, set the endpoint's maxBytes option.
  • Copied content: if your build compiles a copy of the content, highlights appear only once the copy matches the checkout. A deleted file has no page to show its changes on.

gitChangelog: false in frontmatter hides the history sections, but highlighting still works on that page.

To build your own integration, see the Advanced API. If highlights don't appear, see Troubleshooting.

Contributors

Page history