Docusaurus integration
Docusaurus is a docs-site framework (MDX pages, sidebar, search). If you write library docs with it instead of Next.js, use next-live-docusaurus to turn ```tsx live fences into editable previews. Same engine as this playground, wired through Docusaurus's CodeBlock theme.
Try it here#
These run with next-live directly (not inside Docusaurus). Edit the source and watch the preview update. That is what your readers get after you add the plugin.
Registered component: same import path Docusaurus sites use:
Preview
Source (editable)
Hooks + counter: no registry import needed:
Preview
Source (editable)
Playground vs Docusaurus
This page proves the snippets work. The plugin adds the live metastring, SSR-safe
<BrowserOnly> fallback, title/line-number forwarding, and lazy loading so static
fences never pull next-live into the server bundle.
Install#
Requires React 19 and Docusaurus 3.7+ with @docusaurus/core and @docusaurus/theme-common installed in your site.
npm install next-live,next-live-docusaurus,prism-react-renderer
Configure the plugin#
import nextLivePlugin from 'next-live-docusaurus';export default {plugins: [[nextLivePlugin,{ modules: './src/live-modules.ts' },],],};
src/live-modules.ts exports components your snippets may import as @next-live-docusaurus/modules:
import * as React from 'react';export const Button = ({ children }) =>React.createElement('button', { type: 'button' }, children);
Mark a fence as live#
Add the live token to the code fence metastring:
MDX fence opener: ```tsx live
import { Button } from '@next-live-docusaurus/modules';export default function Demo() {return <Button>Hello from Docusaurus</Button>;}
Optional title and line numbers (forwarded from Docusaurus metadata):
MDX fence opener: ```tsx live title="Counter" showLineNumbers
import { useState } from 'react';export default function Counter() {const [n, setN] = useState(0);return <button onClick={() => setN((v) => v + 1)}>{n}</button>;}
Static fences stay static#
The word live inside a quoted title must not activate live mode:
MDX fence opener: ```tsx title="a live demo"
export default function Static() {return <p>Not live</p>;}
The plugin parses metastrings the same way Docusaurus's built-in live-codeblock theme does.
Run the monorepo example locally#
From the repo root (after building both packages):
npm run build -w next-livenpm run build -w next-live-docusaurusmkdir -p examples/docusaurus/.packsnpm pack -w next-live --pack-destination examples/docusaurus/.packsnpm pack -w next-live-docusaurus --pack-destination examples/docusaurus/.packscd examples/docusaurusnpm cinpm run install:packsnpm run buildnpm run serve
Open http://localhost:3456 for one page with live blocks, line numbers, and static title guards.
Automated check (Playwright):
npm run test:smoke
The demo doc uses slug: /, so production output is build/index.html.
