Skip to content

[doc] Add a custom 404 page with absolute URLs (DOC-945) - #64603

Merged
edoakes merged 9 commits into
masterfrom
doc-945-notfound-404-page
Jul 13, 2026
Merged

edoakes merged 9 commits into
masterfrom
doc-945-notfound-404-page

Conversation

@ronny-anyscale

Copy link
Copy Markdown
Contributor

Description

Adds a custom, themed 404 page for the Ray docs.

Read the Docs serves the 404 page's HTML for any missing /en/<version>/... URL while the browser keeps the originally requested (wrong) path. A 404 built with relative hrefs therefore can't load its own theme assets or point users to a working page. This PR gives the 404 page a <base> element pinned to the canonical version root (READTHEDOCS_CANONICAL_URL, falling back to html_baseurl), so every relative URL — theme CSS/JS, the top navigation, the logo, and the recovery links — resolves correctly no matter which path served the page.

The <base> is injected only for the 404 page (via add_custom_assets, in block htmltitle so it precedes all asset tags). No other page's rendering is touched — which is what avoids the sitewide sidebar-href regression that caused the earlier sphinx-notfound-page attempt to be reverted (#63343).

Changes (all under doc/):

  • source/_templates/404.html — themed template (extends !layout.html), injects <base>, custom body with recovery links
  • source/404.rst — :orphan: :nosearch: stub that registers the 404 docname
  • source/_static/css/404.css — centered layout using pydata-sphinx-theme CSS variables (light/dark aware)
  • source/conf.py — pagename == "404" branch in add_custom_assets + "404": [] in html_sidebars

Related issues

Related to DOC-945. Follow-up to the reverted 404 attempt in #63343.

Additional information

Verified locally with an isolated Sphinx build (real pydata-sphinx-theme + the real template/conf logic, READTHEDOCS_CANONICAL_URL set to a preview host):

  • <base> present and positioned before all theme CSS/JS
  • 404 body + recovery links render; <base> appears on 404.html only (not on any other page)

Draft pending the Read the Docs preview regression gate:

  • 404 page renders with working URLs when served from a deep /en/<version>/... path
  • Other pages' <a class="reference internal"> hrefs stay relative — 0/N doubled .//en/<version>/ prefixes

🤖 Generated with Claude Code

Read the Docs serves a docs 404 for any missing /en/<version>/... path
while the browser keeps the originally requested (wrong) URL, so a 404
page built with relative hrefs can't load its own theme assets or send
users back to a working page.

Add a custom, themed 404 page whose <base> element pins the document base
to the canonical version root (READTHEDOCS_CANONICAL_URL, falling back to
html_baseurl), so every relative URL -- theme CSS/JS, the top navigation,
the logo, and the recovery links -- resolves correctly regardless of the
path that served the page.

The <base> is injected only for the 404 page (via add_custom_assets, in
block htmltitle so it precedes all asset tags). No other page's rendering
is touched, which avoids the sitewide sidebar-href regression that
reverted the earlier sphinx-notfound-page attempt (#63343).

- doc/source/_templates/404.html: themed template (extends !layout.html)
- doc/source/404.rst: :orphan: :nosearch: stub to register the docname
- doc/source/_static/css/404.css: centered, theme-variable-based styles
- doc/source/conf.py: 404 branch in add_custom_assets + html_sidebars

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a custom 404 error page for the documentation, adding a dedicated Sphinx source file, a custom HTML template, and associated CSS styling. The configuration in conf.py is updated to hide the sidebar on the 404 page and dynamically resolve the base URL to ensure relative links work correctly. The review feedback identifies two key issues: first, accessing html_baseurl directly instead of via app.config can ignore command-line overrides, and a missing fallback check could cause a build crash if both canonical and base URLs are unset; second, the template uses Remix Icon classes which are not supported by the theme, so they should be replaced with Font Awesome classes to prevent broken icons.

Comment thread doc/source/conf.py Resolved
Comment thread doc/source/_templates/404.html Resolved
ronny-anyscale and others added 6 commits July 8, 2026 12:03
The incremental-from-master-cache PR build path (with the DOC-1314
delete/move guard) was failing on the PR preview independently of the
page content in this branch. Collapse the build.jobs.build.html override
to the clean `make -C doc html` build that branch/tag builds already run,
so PR previews build the same, proven way.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Swap the four hardcoded recovery-link buttons (Documentation home,
Getting started, Install, Examples) for a prominent search field that
opens the site-wide Algolia DocSearch modal already initialized in the
navbar by sphinx-docsearch. The 404 page no longer references any
content-page paths, so it can't rot into dead links when those pages
move or get renamed. Also reword the lead message.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a sentence to the 404 lead paragraph directing users to the search
box to find what they need.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Use app.config.html_baseurl (which respects -D html_baseurl= overrides)
instead of the module global, and fall back to "/" so the 404 handler
can't raise AttributeError if no base URL is configured.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The new-page lint rejects newly added .rst files, so author the 404 stub
as MyST (.md). Faithful conversion: :orphan:/:nosearch: become frontmatter
(orphan: true / nosearch: true), which MyST turns into doc metadata with no
warning under -W. The docname stays "404", so the template swap in
add_custom_assets and the llms_txt_exclude entry are unchanged. Verified an
isolated MyST -W build stays clean and still emits 404.html with the <base>
and templated body.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ronny-anyscale
ronny-anyscale marked this pull request as ready for review July 9, 2026 16:30
@ronny-anyscale
ronny-anyscale requested review from a team as code owners July 9, 2026 16:30

@dstrodtman dstrodtman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

Just confirming: this resolves as a 404 and not a 200/300 code?

We should do follow up work to capture redirect rules that should 404 now that this is live.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a897f4f. Configure here.

Comment thread doc/source/404.md Resolved
@ronny-anyscale

Copy link
Copy Markdown
Contributor Author

Just confirming: this resolves as a 404 and not a 200/300 code?

All signs point to yes...
image

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Jul 9, 2026
@ronny-anyscale ronny-anyscale added the go add ONLY when ready to merge, run all tests label Jul 9, 2026
The 404 page dropped the left nav sidebar via html_sidebars but still
rendered the right-hand page TOC + edit-on-github, so it didn't match the
intended standalone, centered layout the way ray-overview/examples does.
Add html_theme.sidebar_secondary.remove to the 404 frontmatter -- the MyST
equivalent of the :html_theme.sidebar_secondary.remove: field that
examples.rst and index.rst use. Flagged by Cursor Bugbot.

Signed-off-by: Ronny Roland <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@edoakes
edoakes merged commit 27e6354 into master Jul 13, 2026
3 checks passed
@edoakes
edoakes deleted the doc-945-notfound-404-page branch July 13, 2026 16:06
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…#64603)

## Description

Adds a custom, themed **404 page** for the Ray docs.

Read the Docs serves the 404 page's HTML for any missing
`/en/<version>/...` URL while the browser keeps the originally requested
(wrong) path. A 404 built with relative hrefs therefore can't load its
own theme assets or point users to a working page. This PR gives the 404
page a `<base>` element pinned to the canonical version root
(`READTHEDOCS_CANONICAL_URL`, falling back to `html_baseurl`), so every
relative URL — theme CSS/JS, the top navigation, the logo, and the
recovery links — resolves correctly no matter which path served the
page.

The `<base>` is injected **only** for the 404 page (via
`add_custom_assets`, in `block htmltitle` so it precedes all asset
tags). No other page's rendering is touched — which is what avoids the
sitewide sidebar-href regression that caused the earlier
`sphinx-notfound-page` attempt to be reverted (ray-project#63343).

**Changes** (all under `doc/`):
- `source/_templates/404.html` — themed template (extends
`!layout.html`), injects `<base>`, custom body with recovery links
- `source/404.rst` — `:orphan:` `:nosearch:` stub that registers the
`404` docname
- `source/_static/css/404.css` — centered layout using
pydata-sphinx-theme CSS variables (light/dark aware)
- `source/conf.py` — `pagename == "404"` branch in `add_custom_assets` +
`"404": []` in `html_sidebars`

## Related issues

Related to DOC-945. Follow-up to the reverted 404 attempt in ray-project#63343.

## Additional information

Verified locally with an isolated Sphinx build (real pydata-sphinx-theme
+ the real template/conf logic, `READTHEDOCS_CANONICAL_URL` set to a
preview host):
- `<base>` present and positioned **before** all theme CSS/JS
- 404 body + recovery links render; `<base>` appears on `404.html`
**only** (not on any other page)

**Draft pending the Read the Docs preview regression gate:**
- [ ] 404 page renders with working URLs when served from a deep
`/en/<version>/...` path
- [ ] Other pages' `<a class="reference internal">` hrefs stay relative
— `0/N` doubled `.//en/<version>/` prefixes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Ronny Roland <[email protected]>
Signed-off-by: Ronny <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: 400Ping <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants