Skip to content

refactor: remove dead layouts, extract shared utilities, and deduplicate docs routes#1248

Open
jderochervlk wants to merge 7 commits intomasterfrom
vlk/clean-up-dead-code
Open

refactor: remove dead layouts, extract shared utilities, and deduplicate docs routes#1248
jderochervlk wants to merge 7 commits intomasterfrom
vlk/clean-up-dead-code

Conversation

@jderochervlk
Copy link
Copy Markdown
Collaborator

@jderochervlk jderochervlk commented Apr 13, 2026

Note

This work was done with the assistance of AI

A series of refactoring steps that remove dead code, extract shared utilities, and consolidate duplicated layout/sidebar logic across docs route modules. Net result: -374 lines (215 added, 589 removed) across 33 files.

Changes

Dead code removal

  • Delete ApiLayout (unused in any production route) along with its test file
  • Remove unused makeBreadcrumbs, NavItem/Category aliases, and StaticContent module type from DocsLayout
  • Inline ApiOverviewLayout directly into ApiOverviewRoute, then delete the standalone layout module

Shared utility extraction

  • FrontmatterUtils.getField -- replaces ~150 lines of duplicated frontmatter switch blocks across 6 route files
  • TocUtils.buildEntries -- replaces duplicated TOC construction logic across 4 route files
  • DocsSidebar component -- extracts the ~25-line mobile sidebar pattern (used with NavbarTertiary) that was copy-pasted across DocsManualRoute, DocsReactRoute, ApiOverviewRoute, and DocsGuidelinesRoute

Layout route for shared NavbarSecondary

  • New DocsLayoutRoute renders <NavbarSecondary /> + <Outlet /> as a React Router layout route
  • All docs, API, and syntax-lookup routes are nested under it in app/routes.res, removing the duplicated <NavbarSecondary /> from 7 child route modules

LandingPageLayout rename

  • Renamed LandingPageLayout to LandingPage and moved from src/layouts/ to src/components/ -- it is a self-contained page component, not a layout wrapper (it accepts no children)

Screenshot changes explained

All 7 regenerated reference screenshots are expected visual changes caused by two test infrastructure improvements, not regressions:

  1. BrowserRouter replaced with MemoryRouter -- tests now use <MemoryRouter initialEntries=["/docs/manual/api"]> instead of <BrowserRouter> (which defaults to pathname /). This means the sidebar's isItemActive check now correctly matches the "Introduction" nav item, rendering it with the active highlight style. The pagination feature in SidebarLayout also finds the current page in the nav items, so a "Stdlib -->" next-page link now renders in the content area. Both behaviors match production; they were simply invisible in the old tests because no route matched.

  2. Sidebar queries scoped to sidebar-content testId -- because DocsLayout now renders sidebar content that can appear in both the desktop sidebar and the mobile NavbarTertiary dialog, queries like getByText("Stdlib") would match multiple elements. Tests now scope queries to screen->getByTestId("sidebar-content") to target the desktop sidebar specifically.

- Delete ApiLayout component (unused in production routes)
  - Inline makeBreadcrumbs into ApiRoute.res (its only consumer)
  - Remove test file that only tested the dead component
- Clean up DocsLayout: remove unused makeBreadcrumbs, NavItem/Category
  aliases, and StaticContent module type
- Extract FrontmatterUtils.getField to replace ~150 lines of duplicated
  frontmatter switch blocks across 6 route files
- Extract TocUtils.buildEntries to replace duplicated TOC construction
  logic across 4 route files
Add a React Router layout route that renders <NavbarSecondary /> and
<Outlet />, eliminating the duplicated <NavbarSecondary /> from 7 child
route modules.

- Create app/layouts/DocsLayoutRoute.res as a layout route
- Nest all docs, API, and syntax-lookup routes under the layout
- Remove <NavbarSecondary /> from ApiOverviewRoute, ApiRoute,
  DocsGuidelinesRoute, DocsManualRoute, DocsReactRoute,
  SyntaxLookupRoute, and SyntaxLookupDetailRoute
- DocsOverview remains a flat route (it uses MainLayout, not the
  docs sidebar pattern)
- Move categories data directly into ApiOverviewRoute.res
- Replace <ApiOverviewLayout.Docs> with <DocsLayout categories theme=#Js>
- Update tests to use DocsLayout and MemoryRouter
- Delete src/layouts/ApiOverviewLayout.res and .resi
Move from src/layouts/ to src/components/ since it is a self-contained
page component, not a layout wrapper. It does not accept children and
does not provide structural wrapping like the other layouts do.
DocsLayout now owns both the desktop sidebar (via SidebarLayout.Sidebar)
and the mobile sidebar (via NavbarTertiary dialog). Routes pass data
instead of constructing sidebar JSX inline.

- Add ~breadcrumbs and ~editHref props to DocsLayout
- DocsLayout renders NavbarTertiary internally with mobile sidebar
- Simplify DocsManualRoute, DocsReactRoute, ApiOverviewRoute, and
  DocsGuidelinesRoute by removing ~30 lines of duplicated sidebar
  construction and NavbarTertiary rendering from each
- ApiRoute is unchanged (uses a different sidebar structure)
- CommunityRoute is unchanged (already handles both sidebars internally)
DocsLayout now renders NavbarTertiary internally, which creates a mobile
sidebar dialog. This caused two test issues:

- Duplicate element matches: sidebar text appeared in both the desktop
  sidebar and the mobile dialog. Fixed by scoping queries to the
  sidebar-content testId.
- Screenshot dimension mismatches: NavbarTertiary adds height to the
  rendered layout. Regenerated all affected reference screenshots.

Also fixed BrowserRouter -> MemoryRouter in DocsLayout tests per project
conventions.
The previous approach of rendering NavbarTertiary inside DocsLayout
placed it in the wrong DOM position (inside the layout content area
instead of above it), causing visual bugs on mobile and desktop.

Fix by reverting DocsLayout to a simple SidebarLayout wrapper and
extracting the duplicated mobile sidebar JSX into a shared DocsSidebar
component. Routes keep rendering NavbarTertiary at the correct position
(above DocsLayout) but use DocsSidebar to avoid the 25-line copy-paste.

- Create src/components/DocsSidebar.res with shared sidebar content
- Revert DocsLayout to pre-NavbarTertiary state (remove breadcrumbs,
  editHref props and NavbarTertiary rendering)
- Update DocsManualRoute, DocsReactRoute, ApiOverviewRoute, and
  DocsGuidelinesRoute to use DocsSidebar with NavbarTertiary
- Scope ApiOverviewLayout test sidebar queries to sidebar-content
  testId to avoid matching pagination links
- Regenerate reference screenshots
@github-actions
Copy link
Copy Markdown

Cloudflare deployment

Deployement ID: 60eb709e-5357-4f8c-ae10-646db44132bc
Deployment Environment: preview

⛅️ wrangler 4.63.0 (update available 4.82.1)
─────────────────────────────────────────────
✨ Compiled Worker successfully
Uploading... (7383/7847)
Uploading... (7538/7847)
Uploading... (7692/7847)
Uploading... (7847/7847)
✨ Success! Uploaded 464 files (7383 already uploaded) (6.19 sec)

✨ Uploading _redirects
✨ Uploading Functions bundle
🌎 Deploying...
✨ Deployment complete! Take a peek over at https://60eb709e.rescript-lang.pages.dev
✨ Deployment alias URL: https://vlk-clean-up-dead-code.rescript-lang.pages.dev

@jderochervlk jderochervlk changed the title Vlk/clean up dead code refactor: remove dead layouts, extract shared utilities, and deduplicate docs routes Apr 13, 2026
@jderochervlk jderochervlk marked this pull request as ready for review April 13, 2026 17:43
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.

1 participant