Skip to content

feat(content)!: move to Nuxt Content v4 with live content and worker search - #107

Draft
larbish wants to merge 2 commits into
mainfrom
feat/nuxt-content-v4
Draft

larbish wants to merge 2 commits into
mainfrom
feat/nuxt-content-v4

Conversation

@larbish

@larbish larbish commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Moves the layer onto Nuxt Content v4, which brings two features comark-docs carried its own code for:

The layer keeps the webhook's checks and purge, versioned previews, the per-commit routes and ISR.

How the content is declared

The layer declares its content once, in server/content.ts:

import { createNuxtContent, lastCommit } from '@nuxt/content/server'
import forge from 'comark-content/sources/forge'
import fs from 'comark-content/sources/fs'
import markdown from 'comark-content/plugins/markdown'
import yaml from 'comark-content/plugins/yaml'

// Repository, branch and content directory, found from git by `modules/config` at build.
const repository = { provider: github({ auth }), repo: 'comarkdown/comark-docs', ref: 'main', path: 'playground/content' }

export const content = createNuxtContent({
  mode: 'server-only',
  // Production reads GitHub, dev reads the working tree.
  source: import.meta.dev ? fs(contentPath) : forge(repository),
  plugins: [markdown({ comark: { plugins: [mermaid(), highlighter, toc({ depth: 3 }), emoji(), security()] } }), yaml()],
  // Parsed content and the commit being served, shared by every server.
  cache: { driver: contentCacheDriver() },
  // The commit to serve: the last one that touched the content directory.
  live: { ref: lastCommit(repository), maxAge: 60 * 60 },
})

Server code reads it through two auto-imported functions:

// server/routes/rss.xml.get.ts: the content at the commit being served
const docs = await resolveContent(content)
const navigation = await docs.navigation()

// server/api/revalidate.post.ts: after the signature check, move to the new commit
const { from, to, changed, removed, navigation } = await revalidateContent(content)
// { from: '0415709…', to: '9c2e1a4…', changed: ['/getting-started/configuration'], removed: [], navigation: false }

What happens at runtime:

  1. Build: Nuxt Content asks lastCommit() for the commit and reads the files at that commit from GitHub. It ships them parsed in the function, stamped with the commit.
  2. Request: the commit stored in the Runtime Cache is served while it is younger than maxAge. Older or missing, lastCommit() is asked again and the answer is stored. Every server reads the same entry, so a visit never mixes two commits.
  3. Push: the webhook calls revalidateContent(). It stores the new commit, compares the two commits and returns the pages that changed. The layer turns them into URLs (page, payload, raw twin, every page when navigation is true, and the global indexes) and purges them from ISR.
  4. Missed webhook: the stored commit expires after maxAge (1 hour on production, 10 minutes elsewhere), and the next request finds the push.

Pages read the same content through Nuxt Content's client on /__nuxt_content.

How search works

The worker is declared in the layer, so sqlite-wasm stays out of the pages' bundle:

import { createNuxtContentWorker, sqliteFullTextSearch, sqliteWasm } from '@nuxt/content/worker'

export default createNuxtContentWorker({
  plugins: [sqliteFullTextSearch({ database: sqliteWasm() })],
})

useSearch() wraps useNuxtContentWorker() and tells it which commit to load:

// `sha` comes from `/api/content/head` on production, or the preview's head route on `/tree`, `/blob` and `/pr`.
const worker = useNuxtContentWorker({ basePath: () => sha.value ? `/api/content/blob/${sha.value}` : undefined })
  1. The browser asks the head route for the commit, so a cached page can't carry an old one.
  2. The worker loads /api/content/blob/<sha>/snapshot/default.json. That URL never changes for a commit, so ISR keeps it forever, and the webhook warms the new one after a push.
  3. When the commit changes, after a push or when leaving a preview, the worker stops and a new one loads the next commit.
  4. In dev, basePath is unset and the worker reads the dev server, which follows the working tree.

What changed

  • Content: server/content.ts as above. Server routes (RSS, sitemap, llms, agent discovery, MCP, assistant, history, head route, payload ETag) call resolveContent(content).
  • Build values: modules/config passes the repository, branch, content directory and highlighter hash through process.env.COMARK_DOCS_CONTENT, inlined with nitro.replace. server/content.ts also runs at build, outside Nitro, where useRuntimeConfig() doesn't exist.
  • Webhook: gets the changed and removed pages from revalidateContent(). It answers from, to, navigation and pages instead of manifest.
  • Search: app/content.worker.ts and useNuxtContentWorker() as above. The layer's worker, its logger and nuxt-workers are removed.
  • Previews: same routes and rules, pinned with content.withRef(sha).
  • Removed: the Global Config pin and its docs, @sqlite.org/sqlite-wasm, modules/snapshot, utils/factory.ts, the production /api/content/** route, and their tests.
  • Tests: a push test runs the built playground against a mocked GitHub (node --import test/fixtures/github-mock.mjs). Two e2e tests cover the edit link and the RSS dates.

Evidence

A build of main (a3ebf99) and of this branch were served at the same commit, and 88 responses were captured from each. Identical: the text of all 16 pages, status codes, cache headers, ETags, raw twins, llms.txt, llms-full.txt, sitemap.md, rss.xml, previews, and the ISR configs of the Vercel output. /__nuxt_content/list items no longer carry meta.toc, which nothing reads.

✓ serves the last commit touching the content directory
✓ moves to a commit changing one page, and purges that page and the global indexes
✓ purges every page when a title changes
✓ stops serving a deleted page, and purges it
✓ leaves the served commit alone for a push that changes no content

The same test file passes on main. Purge sets: 8 purged and 2 warmed for one page, 60 and 2 for a title change.

Search in a real browser gives the same results as main for vitesse, webhook, pull request and zzzznothing:

  • on production
  • on /blob/96c1546…, where vitesse finds nothing
  • after leaving that preview for production
  • in nuxt dev from a cold Vite cache, and on a dev preview

It also finds a section pushed after the deploy.

JavaScript preloaded per page (gzip): docs pages go from 928,063 to 845,155 bytes, / from 420,222 to 338,642. The old search worker was preloaded on every page, Nuxt Content's isn't.

Notes

  • Draft until feat: serve content at a commit chosen at runtime with live nuxt/content#3936 fixes two bugs. Pinned to @nuxt/content@b771912. CI fails at pnpm dev:prepare on it, and every check and number above was measured with these two fixes applied by hand in node_modules:
    • The module loads server/content.ts without the app's aliases or import.meta.dev: Cannot find module '#comark-docs/highlighter'.
    • v3Enabled() reads import.meta.content?.compatibilityVersion, which nitro.replace doesn't match, so the v3 plugins run with compatibilityVersion: 4. meta.extension becomes md: the edit link breaks, and RSS dates and page history go empty.
  • Server files import content from server/content.ts: the app and the server both auto-import a content, and typed routes make nuxt typecheck resolve the client one.
  • Vercel previews share one live-commits key in the Runtime Cache, so two preview deployments on different branches can serve each other's commit for up to maxAge.
  • pack and consumer fail with ERR_PNPM_NO_MATCHING_VERSION until @nuxt/content v4 is released.
  • Behaviour changes:
    • no content rollback without a git revert
    • the build reads content from GitHub
    • a code-only push costs one GitHub call
    • in dev, raw twins and MCP don't follow edits, and the webhook answers 500
    • /tree/<production branch> follows a push within 10 minutes
    • leaving a preview reloads production's search index
    • the ?debug=search logs are gone
  • Runtime Cache, ISR purge and search after a push are still to be checked on a deployment.

ELI5

The site used to carry its own machinery to decide which version of the docs to show and to search it in the browser. Nuxt Content does both now. When someone pushes a change, the site still updates in seconds, refreshes only the pages that changed, and search follows.

🤖 Generated with Amp, reviewed by @larbish before opening.

…search

BREAKING CHANGE: the Global Config content pin (`GLOBAL_CONFIG`, `contentSha`) is removed. Production content is read from `/__nuxt_content/**`.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21f0d-7e86-7326-bad4-c690c2a760ed
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
comark-docs-layer Error Error Nov 30, 2026 10:31am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Documentation previews

📚 Preview all documentation changes (follows new pushes)

Pinned to the current head: adf103c

# Conflicts:
#	nuxt.config.ts
#	package.json
#	pnpm-lock.yaml

This branch had an error being deployed

1 failed deployment
Preview — adf103c9 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants