Improve docs indexing, accessibility, and initial load performance

Merged
AL
2mo ago
+1378-248

Problem and result

Mounted production builds were overwriting prerendered docs with asset directories and the root SPA shell. This left the docs home without indexable content and six articles returning 404. Other pages repeated metadata, exposed legacy URLs as 200/JavaScript redirects, and loaded substantial code and chart work before readers needed it.

This PR repairs the production output, improves shared docs structure and accessibility, and reduces initial work while preserving interactive examples. The complete final production crawl verifies 418/418 canonical pages, and all 94 legacy redirects resolve correctly.

What changed and why

  • Preserve mounted prerenders: recursively merge assets into the route tree and compress only after the final tree is assembled, so routes named assets/components and the docs home survive the build.
  • Make canonical pages distinct and discoverable: contextual titles/descriptions with normalized standalone acronyms, canonical URLs and structured breadcrumbs using the configured deployment origin/mount and real routes (localhost by default; REFLEX_DEPLOY_URL supplied by deployment jobs), the standard sitemap XML namespace, and frontend-prefix-aware sitemap generation. Fix duplicate H1 content, broken fragments, and missing image alt text.
  • Return real redirects when the backend serves the frontend: GET/HEAD middleware issues permanent 301 responses and retains queries. Static-only hosting gets readable destination links, canonical/noindex metadata, and refresh fallback; CDN edge redirects still need deployment configuration.
  • Render readable code immediately: escaped Shiki fallback code is present in SSR. Download/highlight near the viewport during idle time; failed highlighting leaves code readable. Cached HTML matches every highlighting input, so theme/language/transformer changes immediately restore fallback code until replacement highlighting succeeds. Preserve cleanup on unmount.
  • Reduce initial library work: standard React memo initializers can be discarded when unused, while custom wrappers retain side effects. Add the opt-in frontend_lazy_bundled_libraries configuration and enable it for docs; optional dynamic namespaces load once on demand and retry after failures. Core React/context identity is preserved, and the framework default stays eager for compatibility. Preload global CSS explicitly.
  • Defer expensive examples: the documented demo exec defer flag mounts Plotly previews as readers approach them, reserves space, and preserves server-rendered source. Charts now fit their mobile container. Remove docs-wide marketing pixels/session recorders.
  • Improve shared controls/layout: descriptions render once in responsive API tables; copy buttons, card links, clear controls, mobile navigation, and feedback triggers have valid semantics/names. Eliminate nested feedback buttons, keep card focus outlines inside rounded clipping boundaries, and improve code/counter/status contrast.
  • Isolate project configuration: only the requested project can supply rxconfig, avoiding an unrelated editable docs app changing framework tests or another project. Adjust the invalid-event-value fixture to account for the enterprise plugin's legitimate function serializer. Scope version-check mocks to their consumer so lazy dependency imports still read real package versions. The docs link validator uses the standard sitemap namespace and the configured build directory.

Before and after

CheckBeforeAfter
Docs homeEmpty 14.8 KiB SPA shellFull prerendered content
Broken articles6 return 404All 6 return 200
Canonical crawlMissing home metadata; duplicate titles/descriptions418 unique titles/descriptions, one H1 each, matching canonicals
Legacy routes94 return 200 with JS redirects94 HTTP 301s; all destinations and static fallbacks verified
SitemapInvalid namespace / wrong mounted rootXSD-valid, 418 unique production URLs including docs home
Broken in-page fragments / missing image alt attributes2 / 40 / 0
Structured breadcrumbsNone417 articles
Plotly mobile initial total blocking time5,965 ms0 ms

Lighthouse performance scores (out of 100), before → after:

PageMobileDesktop
Docs home63 → 6889 → 97
Introduction53 → 5781 → 85
Installation47 → 6080 → 86
Chat tutorial55 → 5987 → 89
Button55 → 5775 → 81
Bar chart42 → 5378 → 80
AG Grid44 → 4985 → 79
App API54 → 6081 → 89
Changelog57 → 6188 → 92
HTML layout49 → 5777 → 83
Plotly23 → 5367 → 81

Lighthouse SEO is 100 in all 26 recorded runs. Best practices improved from 54 to 100 except AG Grid (96, due to enterprise trial-license console messages). SEO scores alone missed the original broken/empty pages, so the full raw-HTML crawl is the primary correctness check.

Initial local JavaScript in the HTML/module-preload graph (gzip):

RouteBefore → after
/docs/getting-started/introduction/889 → 798 KiB
/docs/library/forms/button/1070 → 960 KiB
/docs/api-reference/app/586 → 488 KiB
/docs/library/graphing/other-charts/plotly/1076 → 966 KiB

Measurement provenance: the Lighthouse table was recorded on 654132a. The subsequent review fixes change highlighting invalidation, focus outlines, title casing, breadcrumb edge cases, and test fixtures; all 26 performance runs were not repeated after those fixes. The complete 418-page crawl and production browser checks were repeated at fe56d43a. The follow-up in f2a0f434 was checked with the complete docs suite, all four frontend regressions, real app imports under staging URL settings, and separate dev/static frontend redirect checks.

Method: production builds against base bae7294119a8ffa2b3177a0a0f0063d76b616d86, same macOS/Apple M5 Pro machine, Node 26, Chrome 152, Lighthouse 13.4.1 with default simulated throttling and fresh headless Chrome launches. Eleven routes on mobile/desktop; home/introduction mobile scores are medians of three runs, others single runs. All 26 results are included, including regressions. These local measurements are not field Core Web Vitals. The home originally served an empty shell, so its corrected payload is not an equivalent isolated speed comparison.

Validation

  • 8,453 framework unit tests passed, 18 skipped; 76.50% coverage collected from process startup with uv run --no-sync coverage run -m pytest tests/units -q, then coverage report.
  • 449 docs tests passed, 1 skipped, from docs/app.
  • The reflex-docs Python 3.11/3.12 CI jobs now run the frontend suite after the production build, so these checks run on each PR.
  • 4 frontend regressions passed: escaped React SSR, highlight input invalidation/failure/async replacement, Rolldown removal of unused memos/custom-wrapper side effects, and generated lazy-registry execution/concurrency/retry/legacy compatibility.
  • All changed-file pre-commit hooks passed: Ruff formatting/lint, codespell, generated stubs, Pyright, ty, Biome. Full-repository Ruff checks and pyright reflex tests pass; no stub hash changes.
  • Complete production build, 418-page HTML crawl, 94 HTTP/static redirects, sitemap XSD validation, and 26 Lighthouse runs.
  • Browser checks: counter updates, feedback popover with a single submit button, mobile navigation, readable light/dark code, wrapping API rows, and one deferred Plotly chart measuring 308px inside a 308px parent with no page overflow at 390px.

Initial validation coverage detail (654132a): pytest-cov's standard invocation passes all unit tests but reports 71.14% because optional pytest plugins import framework modules before its hook starts. Starting coverage before pytest measures 76.50%; the separate units-plus-docs pytest-cov run measures 72.90%. Earlier CLI failures were resolved by fetching Git history/tags and reinstalling editable packages to replace invalid shallow-clone version metadata. No assertions or coverage thresholds were disabled.

Review notes and limits

  1. AG Grid desktop is 85 → 79 in the final single-run comparison; mobile is 44 → 49. Shared providers, CSS, and example bundles remain substantial. This PR does not claim every page is maximally fast.
  2. Some demo-specific accessibility/table checks and vendor trial warnings remain. No audit checks or vendor errors are suppressed.
  3. Verify redirects/cache behavior in the real hosting stack. The separate XY docs application is not part of this checkout and remains the one missing local cross-application target.
  4. Broad integration and minimum-dependency matrices were not run locally. Unit/docs coverage and production browser verification are complete; the repository CI matrix remains the release gate.
  5. Related open work: #6723 and #6732 overlap accessible controls and code loading (the latter uses build-time Shiki); #6563 addresses namespace tree-shaking with a different approach; #7075 changes same-root config dependency eviction. This PR is based on current main and does not include those branches. Coordinate overlapping changes during review.

Submission checklist

  • Reviewed CONTRIBUTING.md and checked related open PRs.
  • Bug fixes and opt-in performance behavior documented.
  • Regression assertions added; tests and pre-commit checks run.
  • News fragments included for each affected package.
  • Adversarial review completed; limitations and overlap recorded above.

The subsequent a7e412af follow-up removes the hardcoded production origin from docs config, preserves APIs/URLs casing in page titles and sidebar labels, and passes 449 docs tests (1 skipped). The show_built_with_reflex=False setting remains enabled in the docs config to hide the badge.