Skip to content

Refactor docs sidebar to frontend state#6430

Merged
Alek99 merged 3 commits intomainfrom
codex/docs-sidebar-html-state
Apr 30, 2026
Merged

Refactor docs sidebar to frontend state#6430
Alek99 merged 3 commits intomainfrom
codex/docs-sidebar-html-state

Conversation

@Alek99
Copy link
Copy Markdown
Member

@Alek99 Alek99 commented Apr 30, 2026

Summary

  • remove backend SidebarState usage from the docs sidebar
  • replace the Radix accordion sidebar with native HTML details / summary structure
  • derive active sidebar sections from the current route on render, including low-level component docs routes

Why

The docs sidebar was coupled to backend state for category selection and accordion state. This makes the sidebar depend on backend state even though the active/open state can be derived from the frontend route.

Validation

  • python3.13 -m compileall -q docs/app/reflex_docs/templates/docpage/sidebar
  • git diff --check -- docs/app/reflex_docs/templates/docpage/sidebar/sidebar.py docs/app/reflex_docs/templates/docpage/sidebar/state.py
  • browser-use check on /docs/library/forms/input/low/ confirmed the Forms sidebar group stays open and Input remains active on the Low Level page

@Alek99 Alek99 changed the title [codex] Refactor docs sidebar to frontend state Refactor docs sidebar to frontend state Apr 30, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 30, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing codex/docs-sidebar-html-state (1a52359) with main (5496439)

Open in CodSpeed

@Alek99
Copy link
Copy Markdown
Member Author

Alek99 commented Apr 30, 2026

#6405

@Alek99 Alek99 requested a review from carlosabadia April 30, 2026 18:33
@Alek99 Alek99 marked this pull request as ready for review April 30, 2026 18:33
@Alek99 Alek99 requested a review from a team as a code owner April 30, 2026 18:33
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR removes the SidebarState Reflex backend state class and replaces the Radix accordion sidebar with native HTML <details>/<summary> elements, deriving all active/open state from the current route URL at render time. The refactoring is well-executed — normalize_url correctly handles /low sub-routes, calculate_index feeds static list[int] indexes instead of reactive Vars, and the @rx.memo removal is appropriate since no Var arguments remain.

Confidence Score: 4/5

Safe to merge; only minor style issues found, no logic or runtime errors.

P2s only — a leftover bare # separator comment and a redundant normalize_url call inside sidebar_comp. Core logic for URL normalization, index calculation, and open-state derivation is correct and idempotent.

No files require special attention.

Important Files Changed

Filename Overview
docs/app/reflex_docs/templates/docpage/sidebar/sidebar.py Major refactor replacing Radix accordion + SidebarState with native HTML details/summary and static Python logic; two minor P2 style issues (bare # separator, redundant normalize_url call)
docs/app/reflex_docs/templates/docpage/sidebar/state.py SidebarState rx.State class and its temporal event handler removed entirely; only pure dataclasses remain — clean simplification with no issues

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["sidebar(url)"] --> B["normalize_url(url)"]
    B --> C["calculate_index × 16\n(all index lists)"]
    C --> D["sidebar_comp(url, ...indexes...)"]
    D --> E["normalize_url(url) again\n⚠ redundant"]
    E --> F{Route type?}
    F -->|"/hosting/"| G["Cloud categories + Cloud content"]
    F -->|"/ai/"| H["AI Builder categories\n+ AI/MCP content"]
    F -->|else| I["Learn/Components/API/Enterprise\ncategories + matching content"]
    I --> J{docs_category}
    J -->|0| K["Onboarding · UI · State · Recipes"]
    J -->|1| L["Core · Graphing · Other · Custom"]
    J -->|2| M["API Reference"]
    J -->|3| N["Enterprise Usage · Components"]
    D --> O["sidebar_item_comp"]
    O --> P{has children?}
    P -->|no| Q["sidebar_leaf\nstatic is_active bool"]
    P -->|yes| R["rx.el.details open=is_open\nnative HTML disclosure"]
Loading

Comments Outside Diff (1)

  1. docs/app/reflex_docs/templates/docpage/sidebar/sidebar.py, line 434-436 (link)

    P2 Leftover bare # separator comment

    The bare # comment between skills_index and cli_ref_index appears to be a leftover from when the removed tutorials_index parameter sat between them. With tutorials_index gone, the separator serves no purpose and should be removed.

    Rule Used: Remove commented-out code before merging PRs. (source)

    Learned From
    reflex-dev/reflex-web#1619

Reviews (1): Last reviewed commit: "Format docs sidebar refactor" | Re-trigger Greptile

# Handle sidebar categories for docs/cloud first
rx.cond( # pyright: ignore [reportCallIssue]
_is_docs_hosting,
path = normalize_url(url)
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.

P2 Redundant normalize_url call

sidebar_comp is only ever called from sidebar(), which already passes normalized_url. Calling normalize_url(url) here again is redundant — the result (path) equals url. Consider removing the second call and using url directly for the path-based checks, or document the defensive intent with a comment.

Suggested change
path = normalize_url(url)
path = url # already normalized by sidebar()

@Alek99 Alek99 merged commit 0f46c0e into main Apr 30, 2026
68 of 69 checks passed
@Alek99 Alek99 deleted the codex/docs-sidebar-html-state branch April 30, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants