mdBook Relative Path Navigation Issue (v0.4.41+)
Problem Description
When using mdBook version 0.4.41 or higher, clicking on any link in the sidebar causes all subsequent sidebar links to have incorrect relative paths appended to them, resulting in 404 errors.
Steps to Reproduce
- Build a book with mdBook v0.4.41 or higher where chapters are organized in subdirectories
- Navigate to the book's index page
- Click on any sidebar link that points to a page in a subdirectory (e.g.,
/awareness/index.html)
- Observe that all other sidebar links now have the subdirectory path appended (e.g., all links become
./awareness/...)
Example
- Initial state: All sidebar links work correctly
- Click on:
https://example.com/awareness/index.html
- Result: All sidebar links are now broken:
./intro/introduction.html becomes ./awareness/intro/introduction.html (404)
./wallet-security/index.html becomes ./awareness/wallet-security/index.html (404)
Root Cause
The issue was introduced in mdBook v0.4.41 with PR #2414, which changed how the sidebar is loaded. The sidebar is now loaded from a separate JavaScript file to reduce file size, but this change broke relative path handling when navigating between pages in different subdirectories.
Technical Details
- Affected versions: mdBook v0.4.41 and higher
- Not affected: mdBook v0.4.40 and lower
- Related issues:
Current Workaround
We've reverted to using mdBook v0.4.40, which does not have this issue. This is a stable version without known security vulnerabilities (the last mdBook CVE was fixed in v0.4.5).
Implementation
In our vercel_build.sh:
# Download and extract mdBook
echo "Downloading mdBook v0.4.40..."
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
Attempted Solutions That Did Not Work
- Creating an index.md file - While this addresses some mdBook issues with first chapter as index, it doesn't fix the sidebar path problem
- Setting
site-url = "/" in book.toml - The site-url configuration doesn't rewrite markdown links as expected
- Updating custom theme files - The issue is in mdBook's core sidebar loading mechanism
Environment
- mdBook versions tested: v0.4.40 (works), v0.4.41-v0.4.52 (broken)
- Deployment: Vercel
- Book structure: Multiple chapters organized in subdirectories
- Theme: Custom theme with mdbook-admonish and other plugins
mdBook Relative Path Navigation Issue (v0.4.41+)
Problem Description
When using mdBook version 0.4.41 or higher, clicking on any link in the sidebar causes all subsequent sidebar links to have incorrect relative paths appended to them, resulting in 404 errors.
Steps to Reproduce
/awareness/index.html)./awareness/...)Example
https://example.com/awareness/index.html./intro/introduction.htmlbecomes./awareness/intro/introduction.html(404)./wallet-security/index.htmlbecomes./awareness/wallet-security/index.html(404)Root Cause
The issue was introduced in mdBook v0.4.41 with PR #2414, which changed how the sidebar is loaded. The sidebar is now loaded from a separate JavaScript file to reduce file size, but this change broke relative path handling when navigating between pages in different subdirectories.
Technical Details
Current Workaround
We've reverted to using mdBook v0.4.40, which does not have this issue. This is a stable version without known security vulnerabilities (the last mdBook CVE was fixed in v0.4.5).
Implementation
In our
vercel_build.sh:Attempted Solutions That Did Not Work
site-url = "/"in book.toml - The site-url configuration doesn't rewrite markdown links as expectedEnvironment