Core MainMenu Refactor#13833
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
4a73c01 to
91f75cb
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements a core refactor of the MainMenu component, replacing BaseWeb's StatefulMenu with a custom data-driven implementation. The refactor introduces a cleaner separation of concerns with pure functions for menu data construction and a section-based data model.
Changes:
- Replaced BaseWeb's
StatefulMenuwith custom button-based menu items while retainingStatefulPopoverfor positioning - Introduced pure data model (
MenuItemConfig,MenuSection) and builder functions for menu construction - Refactored styled components from complex nested selectors to simpler button-based styles
- Updated all tests (unit and E2E) to work with the new implementation
Reviewed changes
Copilot reviewed 8 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/lib/src/theme/primitives/sizes.ts |
Added appMainMenu size constant (12rem) for menu width |
frontend/app/src/components/MainMenu/styled-components.ts |
Complete refactor: removed old BaseWeb-style overrides, added new button-based components (StyledMenuItemRow, StyledMenuItemContent, etc.) |
frontend/app/src/components/MainMenu/MainMenu.tsx |
Core refactor: introduced data-driven architecture with pure builder functions, memoized components, and simplified logic |
frontend/app/src/components/MainMenu/mainMenuTestHelpers.ts |
Updated test helpers to use userEvent and new test IDs, simplified API |
frontend/app/src/components/MainMenu/MainMenu.test.tsx |
Comprehensive test updates with excellent coverage of all menu scenarios, proper use of async/await |
frontend/app/src/App.test.tsx |
Updated to use new test helper API |
e2e_playwright/st_set_page_config_test.py |
Updated E2E tests to use new menu structure and test IDs |
e2e_playwright/main_menu_test.py |
Updated E2E tests, added Escape key test, fixed label references |
e2e_playwright/__snapshots__/**/*.png |
Updated visual regression test snapshots |
SummaryThis PR refactors the
This is a foundational PR for a MainMenu redesign, with accessibility improvements noted for a follow-up PR. Code QualityThe refactoring follows React best practices well: Strengths:
Minor observations:
The styled components cleanup removes ~120 lines of unused code, which improves maintainability. Test CoverageUnit Tests (MainMenu.test.tsx):
E2E Tests:
Gap: No unit test for the Backwards CompatibilityUser-visible change:
This is a deliberate design change and is backwards compatible in terms of functionality - no API changes or breaking changes to The menu item ordering remains consistent with the existing behavior, and all configurable menu items ( Security & RiskNo security concerns identified:
Low risk items:
AccessibilityCurrent state:
Concerns requiring follow-up (as noted in PR description):
"&:hover, &:focus-visible": {
backgroundColor: theme.colors.darkenedBgMix15,
},
// TODO(accessibility): Add visible focus ring for keyboard navigation.
"&:focus-visible": {
outline: "none",
},
These are acknowledged for a follow-up PR but should be tracked. Recommendations
VerdictAPPROVED: This is a well-executed refactoring that improves code maintainability through a data-driven approach while maintaining backwards compatibility. The test coverage is comprehensive, and the acknowledged accessibility gaps are planned for a follow-up PR. The code follows React best practices and the Streamlit codebase conventions. This is an automated AI review using |
📉 Python coverage change detectedThe Python unit test coverage has decreased by 0.0024%
✅ Coverage change is within normal range. Coverage by files
|
797fe32 to
486ccf5
Compare
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.1500%
💡 Consider adding more unit tests to maintain or improve coverage. |
SummaryThis PR refactors the main menu into a data-driven, sectioned structure with new styled button rows, updates the "Record screen" label, adds a menu width theme primitive, and refreshes e2e snapshots. It also updates frontend and e2e tests, including a new Escape-to-close test. Code QualityOverall structure is cleaner: menu data generation is separated from rendering, and the menu layout is easier to reason about and extend. The new helper utilities and tests read well and align with existing patterns. Test CoverageFrontend unit tests were updated for the refactored menu (including minimal mode and host items). E2E coverage includes updated snapshots and a new Escape-to-close test for the menu. No Python unit tests were required for these changes. Backwards CompatibilityNo public API or protobuf changes detected. This is primarily a UI refactor with updated menu labels and layout, which should be backwards compatible for users. Security & RiskNo new security-sensitive flows identified in this change set. AccessibilityThe menu item buttons remove visible focus outlines without replacing them, which breaks keyboard focus visibility and violates our a11y guidelines. Recommendations
VerdictCHANGES_REQUESTED: Add a visible focus style for menu item buttons to meet accessibility requirements. This is an automated AI review using |
| // Host menu items - injected by host (e.g., Streamlit Cloud) | ||
| // Some host items are hidden if developer settings conflict | ||
| for (const hostItem of hostMenuItems) { | ||
| if (hostItem.type === "separator") continue |
There was a problem hiding this comment.
question: The codex review complains that the new code just ignores the separators provided by host. Is this intended? Maybe add a comment here.
Core refactor of the `MainMenu` component that replaces BaseWeb's `StatefulMenu` with a custom data-driven implementation. This is the foundational PR for the `MainMenu` redesign, going into the feature branch for incremental review. - Remove `StatefulMenu` from BaseWeb, keep `StatefulPopover` for positioning/focus lock - Introduce section-based data model (`MenuSection`, `MenuItemConfig`) - Pure functions for menu construction (`buildMenuData`,`buildMenuSections`, `buildCommonItems`, etc.) - Memoized `MenuContent` component with stable callbacks
Core refactor of the `MainMenu` component that replaces BaseWeb's `StatefulMenu` with a custom data-driven implementation. This is the foundational PR for the `MainMenu` redesign, going into the feature branch for incremental review. - Remove `StatefulMenu` from BaseWeb, keep `StatefulPopover` for positioning/focus lock - Introduce section-based data model (`MenuSection`, `MenuItemConfig`) - Pure functions for menu construction (`buildMenuData`,`buildMenuSections`, `buildCommonItems`, etc.) - Memoized `MenuContent` component with stable callbacks
Core refactor of the `MainMenu` component that replaces BaseWeb's `StatefulMenu` with a custom data-driven implementation. This is the foundational PR for the `MainMenu` redesign, going into the feature branch for incremental review. - Remove `StatefulMenu` from BaseWeb, keep `StatefulPopover` for positioning/focus lock - Introduce section-based data model (`MenuSection`, `MenuItemConfig`) - Pure functions for menu construction (`buildMenuData`,`buildMenuSections`, `buildCommonItems`, etc.) - Memoized `MenuContent` component with stable callbacks
Core refactor of the `MainMenu` component that replaces BaseWeb's `StatefulMenu` with a custom data-driven implementation. This is the foundational PR for the `MainMenu` redesign, going into the feature branch for incremental review. - Remove `StatefulMenu` from BaseWeb, keep `StatefulPopover` for positioning/focus lock - Introduce section-based data model (`MenuSection`, `MenuItemConfig`) - Pure functions for menu construction (`buildMenuData`,`buildMenuSections`, `buildCommonItems`, etc.) - Memoized `MenuContent` component with stable callbacks
This PR is the culmination of the following PRs approved into this feature branch: - [Core `MainMenu` Refactor](#13833) - [`MainMenu` accessibility improvements](#13878) - [Add theme switcher to `MainMenu`](#13937) - [Add auto-rerun toggle to `MainMenu`](#13988) - [Add version footer to `MainMenu`](#14028) - [Remove `SettingsDialog`](#14048)
Describe your changes
Core refactor of the
MainMenucomponent that replaces BaseWeb'sStatefulMenuwith a custom data-driven implementation. This is the foundational PR for theMainMenuredesign, going into the feature branch for incremental review.StatefulMenufrom BaseWeb, keepStatefulPopoverfor positioning/focus lockMenuSection,MenuItemConfig)buildMenuData,buildMenuSections,buildCommonItems, etc.)MenuContentcomponent with stable callbacksNote: Specific accessibility improvements will be made in a follow up PR. Should also get some bundle improvements in follow ups as well.
Before:


After:


Testing Plan