ruby-sdk/docs
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Koichi ITO c2879fb640 Fix flash of unstyled content when loading the docs site
## Motivation and Context

Opening https://ruby.sdk.modelcontextprotocol.io/ briefly showed a black half-circle
at the bottom of the screen. The theme preference script in `head_custom.html` called
`window.jtd.setTheme` on every page load. That helper rewrites the `href` of
the render-blocking color stylesheet link, which detaches the loaded stylesheet
and refetches it, so the page paints unstyled until the replacement arrives.
During that window the search magnifier SVG, sized only by CSS, rendered at its fallback size
and appeared as a large black half-circle near the bottom of the viewport.

The site sets no `color_scheme`, so the default stylesheet is identical to the light one
and most visitors paid the flash for a no-op swap.

This change replaces the `jtd.setTheme` call with a local swapper that:

- Leaves the stylesheet untouched when the resolved theme already matches
  (treating `default` as `light`).
- Swaps non-destructively otherwise: the new link is inserted next to the current one
  and the old link is removed only after the new stylesheet has loaded. On error the new link
  is dropped and the page keeps its current styles.
- Sets `blocking="render"` on the new link so supporting browsers hold first paint until
  the dark stylesheet arrives.

It also pre-applies the dark background and text colors in `custom.scss`, keyed on
the `data-theme` attribute that is set synchronously in the head, to soften the light-colored
first paint for dark-preference visitors in browsers without `blocking="render"` support.

## How Has This Been Tested?

Mirrored the live site locally, patched the inline script with the new code,
and drove it in Chrome:

- Unpatched baseline reproduced the old behavior: the link `href` was rewritten
  and `just-the-docs-light.css` was fetched in addition to `just-the-docs-default.css`.
- Patched light and system-light loads keep the original link untouched with no extra stylesheet request.
- Patched dark loads settle on a single `just-the-docs-dark.css` link, with `jtd.getTheme()`
  still reporting the right theme.
- Rapid toggling keeps at most two color stylesheet links and settles on exactly one matching
  the final preference.
- With `just-the-docs-dark.css` returning 404, the failed link is dropped and the page stays styled.

## Breaking Changes

None.
2026-07-30 12:44:28 +09:00
..
_includes Fix flash of unstyled content when loading the docs site 2026-07-30 12:44:28 +09:00
_sass/custom Fix flash of unstyled content when loading the docs site 2026-07-30 12:44:28 +09:00
assets docs: add dark mode support 2026-05-11 08:46:40 -04:00
latest Add API documentation with GitHub Pages deployment 2025-11-21 12:21:38 -06:00
_config.yml docs: add dark mode support 2026-05-11 08:46:40 -04:00
building-clients.md Bound stdio frame reads with max_line_bytes 2026-07-05 21:30:28 +09:00
building-servers.md Support class-based Resource and ResourceTemplate definitions 2026-07-10 22:39:42 +09:00
CNAME [Doc] Add CNAME file to preserve custom domain across deployments 2026-03-30 13:27:58 +09:00
index.md [Doc] Update homepage with just-the-docs theme 2026-04-15 22:48:15 +09:00
installation.md [Doc] Update homepage with just-the-docs theme 2026-04-15 22:48:15 +09:00