MDX Notes
How to version your docs in Docusaurus — creating snapshots, version dropdowns, versioned sidebars, and keeping multiple versions sane
If you ship a library or API, your users might be on different versions. Docusaurus has built-in versioning that lets you freeze a snapshot of your docs whenever you release, so v1 users still find v1 docs.
How Versioning Works
Think of it as snapshots. Every time you "cut" a version, Docusaurus copies your current docs into a timestamped folder:
docs/— Always the "next" (unreleased/development) versionversioned_docs/version-X.X/— Frozen snapshots of previous versionsversioned_sidebars/version-X.X-sidebars.json— Sidebar configs for each version
Creating Versions
Your First Version
Ready to ship v1.0? One command:
npx docusaurus docs:version 1.0This does three things:
- Copies the entire
docs/folder toversioned_docs/version-1.0/ - Copies
sidebars.jstoversioned_sidebars/version-1.0-sidebars.json - Adds
"1.0"to theversions.jsonfile
:::tip[When to Create a Version] Create a new version whenever you release a major or minor version of your software. Patch releases typically don't need new doc versions — just update the current version's docs. :::
Subsequent Versions
As your project grows:
# After releasing v2.0
npx docusaurus docs:version 2.0
# After releasing v3.0
npx docusaurus docs:version 3.0versions.json tracks them all:
:::note The first entry in versions.json is the "current" (latest stable) version. The docs/ folder is always the "next" (unreleased) version. :::
Version Dropdown
Docusaurus gives you a version switcher dropdown for the navbar:
Visual Result: A dropdown appears in the top-right navbar showing the current version (e.g., "3.0"). Clicking it reveals all available versions plus a link to the versions overview page. The active version is marked with a checkmark.
Customizing Version Labels
Version Banners
Docusaurus automatically shows warning banners on older versions:
| Banner Type | Display |
|---|---|
'none' | No banner |
'unreleased' | "This is unreleased documentation" (for next) |
'unmaintained' | "This version is no longer maintained" |
Visual Result: A yellow banner appears at the top of older version pages stating "This is documentation for version X.X, which is no longer actively maintained." with a link to the latest version.
Versioned Sidebars
Each version gets its own sidebar config. You can restructure navigation between versions if you need to:
:::caution[Editing Versioned Sidebars] The versioned sidebar files are JSON (not JavaScript). You can edit them directly, but be careful — errors in these files will break the build for that version. :::
Version-Specific Content
Conditional Content by Version
Build a component that shows content only for specific versions:
import React from 'react';
import { useDocsVersion } from '@docusaurus/theme-common/internal';
export function VersionOnly({ version, children }) {
const { version: currentVersion } = useDocsVersion();
if (currentVersion === version) {
return <>{children}</>;
}
return null;
}
export function SinceVersion({ version, children }) {
return (
<div className="since-version">
<span className="badge badge--info">Since v{version}</span>
{children}
</div>
);
}import { SinceVersion } from '@site/src/components/VersionOnly';
## API Methods
### fetchData()
Retrieves data from the server.
<SinceVersion version="2.0">
### streamData()
Real-time data streaming with WebSocket fallback.
</SinceVersion>Version-Specific Admonitions
// Before (v2.x) const response = await fetchData('/api/users'); const data = await response.json();
// After (v3.0+) const { data, error } = await fetchData('/api/users');
:::Maintaining Multiple Versions
Strategy 1: Edit in docs/, Backport When Needed
This is the recommended approach:
- Make all changes in
docs/(the next/development version) - When a fix applies to older versions, manually copy it to
versioned_docs/version-X.X/ - Only backport critical fixes (typos, broken links, security notes)
Strategy 2: Minimal Versioned Docs
Only version pages that actually change between releases:
Deleting Old Versions
To remove a version you no longer want to host:
- Delete the folder from
versioned_docs/version-X.X/ - Delete the sidebar file
versioned_sidebars/version-X.X-sidebars.json - Remove the entry from
versions.json
# Remove version 1.0
rm -rf versioned_docs/version-1.0
rm versioned_sidebars/version-1.0-sidebars.json
# Edit versions.json to remove "1.0"Migration Between Versions
Creating a Migration Guide
# Migration Guide: v2 to v3
## Breaking Changes
### 1. New Return Types
| Method | v2 Return | v3 Return |
|--------|-----------|-----------|
| `fetchData` | `Promise<Response>` | `Promise<Result>` |
| `subscribe` | `Subscription` | `AsyncIterator` |
### 2. Removed APIs
The following APIs have been removed in v3:
- ~~`legacyFetch()`~~ → Use `fetchData()` instead
- ~~`syncRequest()`~~ → Use `await fetchData()` instead
### 3. Configuration Changes// v2 configuration module.exports = { // remove-next-line plugins: ['@docusaurus/plugin-legacy'], // add-next-line plugins: ['@docusaurus/plugin-modern'], };
Linking Between Versions
Build Performance with Many Versions
:::caution[Build Time Warning] Each version multiplies your build time. A site with 100 docs pages and 5 versions builds 500 pages. Consider these optimizations: :::
Best Practices for Versioning
:::tip[Versioning Tips]
- Version sparingly — Only create versions for major/minor releases
- Keep
docs/clean — It represents your upcoming release - Use banners — Help users know when they're viewing old docs
- Limit active versions — Maintain 2-3 versions max; archive the rest
- Automate with CI — Create versions as part of your release pipeline
- Document migrations — Every version should have a migration guide
- Test all versions — Include older versions in your CI build checks
:::
Versioning keeps your docs useful to everyone, regardless of which release they're on. Just don't go overboard — maintaining too many versions gets painful fast. Keep 2-3 active, archive the rest, and always provide migration guides.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Document Versioning in Docusaurus.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this MDX Tutorial topic.
Search Terms
mdx-tutorial, mdx tutorial, mdx, tutorial, docusaurus, versioning, document versioning in docusaurus
Related MDX Tutorial Topics