Skip to content

feat(docs): server-render docs behind a persistent sidebar with hash deep-link scrolling - #61

Merged
pulkitxm merged 3 commits into
mainfrom
feat/docs-server-rendered
Jul 24, 2026
Merged

pulkitxm merged 3 commits into
mainfrom
feat/docs-server-rendered

Conversation

@pulkitxm

Copy link
Copy Markdown
Member

Persist the doc tree in a docs layout, server-render the read view and tree data via hydration, and auto-scroll hash deep links into view.

pulkitxm added 2 commits July 24, 2026 15:33
Move the doc tree into a docs layout so it stays mounted across doc
navigation instead of remounting and flashing. Server-render the list
into the sidebar and hydrate the doc read view through a server prefetch,
so first paint is complete and loading skeletons cover only the content
pane.
The browser's native hash scroll fires before the doc content and its
heading ids exist, so a link like /d/<token>#a-heading lands at the top.
Scroll the matching heading into view once the reader mounts and whenever
the hash changes, on both the public and internal reading views.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b704d8ec-30e2-4d34-a260-10729f0af3be

📥 Commits

Reviewing files that changed from the base of the PR and between d4d5ded and c0b9f1a.

📒 Files selected for processing (6)
  • apps/web/src/app/api/docs/route.ts
  • apps/web/src/features/docs/doc-reader.tsx
  • apps/web/src/features/docs/doc-surface.tsx
  • apps/web/src/features/docs/use-hash-scroll.test.tsx
  • apps/web/src/lib/api/docs.ts
  • apps/web/src/lib/query/docs-prefetch.ts
📝 Walkthrough

Walkthrough

The docs area now uses shared shell and sidebar components, route-level React Query hydration, a permission-aware empty pane, pane-specific loading skeletons, centralized list payload construction, and hash-based heading navigation.

Changes

Docs data hydration

Layer / File(s) Summary
Shared docs data hydration
apps/web/src/lib/api/docs.ts, apps/web/src/lib/query/docs-prefetch.ts, apps/web/src/app/api/docs/route.ts, apps/web/src/app/(app)/docs/layout.tsx, apps/web/src/app/(app)/docs/[id]/page.tsx
Docs list payload construction is centralized, validated, and dehydrated for list and detail route hydration.
Docs shell and sidebar state
apps/web/src/features/docs/use-docs-tree.ts, apps/web/src/features/docs/docs-shell.tsx, apps/web/src/features/docs/docs-sidebar.tsx, apps/web/src/features/docs/*sidebar.test.tsx, apps/web/src/components/keyboard-hints.test.tsx
The docs shell provides tree state, while the sidebar handles search, collection mutations, responsive display, navigation, and writable create-document hotkeys.
Docs pages and document pane
apps/web/src/app/(app)/docs/page.tsx, apps/web/src/features/docs/docs-empty-pane.tsx, apps/web/src/features/docs/doc-surface.tsx, apps/web/src/features/docs/docs-skeleton.tsx, apps/web/src/app/(app)/docs/loading.tsx, apps/web/src/app/(app)/docs/[id]/loading.tsx, apps/web/src/features/docs/docs-skeleton.test.tsx
The index page renders a permission-aware empty pane, document routes render hydrated DocSurface, and loading states use DocPaneSkeleton.
Heading identifiers and hash scrolling
apps/web/src/features/docs/use-hash-scroll.ts, apps/web/src/features/docs/doc-reader.tsx, apps/web/src/features/docs/outline.test.ts, apps/web/src/features/docs/use-hash-scroll.test.tsx
Markdown headings receive deterministic IDs, and DocReader scrolls to decoded URL hash targets while respecting reduced-motion preferences.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DocsRoute
  participant DocsLayout
  participant DocsSidebar
  participant DocSurface
  participant DocsQuery
  DocsRoute->>DocsLayout: render docs route
  DocsLayout->>DocsQuery: prefetch docs list
  DocsQuery-->>DocsLayout: dehydrated list state
  DocsLayout->>DocsSidebar: render sidebar with write permission
  DocsRoute->>DocsQuery: prefetch document detail
  DocsQuery-->>DocSurface: hydrated document state
  DocsSidebar->>DocsRoute: navigate to selected document or new document
Loading

Possibly related PRs

  • Noveum/orbit#40: Modifies overlapping docs UI components, including doc-surface.tsx and doc-reader.tsx.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: persistent docs sidebar, server-rendered docs, and hash deep-link scrolling.
Description check ✅ Passed The description is directly aligned with the PR’s goals around persistent layout, hydration, and hash scrolling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/docs-server-rendered

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/app/(app)/docs/[id]/page.tsx (1)

10-25: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate the route parameters before fetching.

id and edit are URL-controlled values. Parse them with a shared Zod schema before passing id to dehydratedDoc or deriving edit mode.

As per coding guidelines, validate every external input with Zod.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/`(app)/docs/[id]/page.tsx around lines 10 - 25, Update
DocPage to validate the resolved route and query values with the shared Zod
schema before using them: validate id before passing it to dehydratedDoc, and
validate edit before deriving startEditing. Reuse the repository’s existing
schema/validation conventions and use the parsed values rather than the raw
URL-controlled inputs.

Source: Coding guidelines

🧹 Nitpick comments (1)
apps/web/src/features/docs/use-hash-scroll.test.tsx (1)

77-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for hashchange.

The suite currently verifies initial mount scrolling and the empty-hash case, but not the listener path introduced by useHashScroll. Render the reader first, change the hash afterward, and assert that the matching heading scrolls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/features/docs/use-hash-scroll.test.tsx` around lines 77 - 89,
Add a regression test in the “reader hash deep link” suite that renders via
renderReader with no initial hash, changes window.location.hash afterward to a
known heading such as rules, and waits for scrolled to contain that heading.
Exercise the useHashScroll hashchange listener path rather than only initial
mount behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/app/api/docs/route.ts`:
- Around line 5-6: Validate searchParamsOf(request) with the shared docs-list
filter Zod schema in the GET handler before passing it to docListPayload. In
apps/web/src/lib/api/docs.ts lines 8-10, replace the filter: unknown parameter
with the schema-inferred filter type; update both affected sites accordingly.

In `@apps/web/src/features/docs/doc-reader.tsx`:
- Line 49: Update the useHashScroll readiness token in the document reader to
include the current document’s identity along with the joined heading IDs.
Preserve the existing heading-ID behavior while ensuring navigation to a
different document produces a distinct token even when headings and URL hash are
unchanged.

In `@apps/web/src/features/docs/doc-surface.tsx`:
- Around line 132-134: Update the useEffect that sets unsavedDocId in the
document surface to return a cleanup function that calls setUnsavedDocId(null)
when the pane unmounts or its dependencies change, while preserving the existing
marker-setting behavior.

In `@apps/web/src/lib/query/docs-prefetch.ts`:
- Around line 19-27: Update the detail-fetch error handling around getDoc in
docs-prefetch.ts to catch only the typed not-found domain error and return null
for that case. Ensure authorization, database, rendering, and all other failures
are rethrown so they reach the request’s error handling path, using the typed
error symbol from `@orbit/shared/errors`.

---

Outside diff comments:
In `@apps/web/src/app/`(app)/docs/[id]/page.tsx:
- Around line 10-25: Update DocPage to validate the resolved route and query
values with the shared Zod schema before using them: validate id before passing
it to dehydratedDoc, and validate edit before deriving startEditing. Reuse the
repository’s existing schema/validation conventions and use the parsed values
rather than the raw URL-controlled inputs.

---

Nitpick comments:
In `@apps/web/src/features/docs/use-hash-scroll.test.tsx`:
- Around line 77-89: Add a regression test in the “reader hash deep link” suite
that renders via renderReader with no initial hash, changes window.location.hash
afterward to a known heading such as rules, and waits for scrolled to contain
that heading. Exercise the useHashScroll hashchange listener path rather than
only initial mount behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 125b7a23-9c28-4ea0-8667-0acd73178576

📥 Commits

Reviewing files that changed from the base of the PR and between f1eb32f and d4d5ded.

📒 Files selected for processing (22)
  • apps/web/src/app/(app)/docs/[id]/loading.tsx
  • apps/web/src/app/(app)/docs/[id]/page.tsx
  • apps/web/src/app/(app)/docs/layout.tsx
  • apps/web/src/app/(app)/docs/loading.tsx
  • apps/web/src/app/(app)/docs/page.tsx
  • apps/web/src/app/api/docs/route.ts
  • apps/web/src/components/keyboard-hints.test.tsx
  • apps/web/src/features/docs/doc-reader.tsx
  • apps/web/src/features/docs/doc-surface.tsx
  • apps/web/src/features/docs/docs-empty-pane.tsx
  • apps/web/src/features/docs/docs-shell.tsx
  • apps/web/src/features/docs/docs-sidebar.test.tsx
  • apps/web/src/features/docs/docs-sidebar.tsx
  • apps/web/src/features/docs/docs-skeleton.test.tsx
  • apps/web/src/features/docs/docs-skeleton.tsx
  • apps/web/src/features/docs/docs-workspace.tsx
  • apps/web/src/features/docs/outline.test.ts
  • apps/web/src/features/docs/use-docs-tree.ts
  • apps/web/src/features/docs/use-hash-scroll.test.tsx
  • apps/web/src/features/docs/use-hash-scroll.ts
  • apps/web/src/lib/api/docs.ts
  • apps/web/src/lib/query/docs-prefetch.ts
💤 Files with no reviewable changes (1)
  • apps/web/src/features/docs/docs-workspace.tsx

Comment thread apps/web/src/app/api/docs/route.ts Resolved
Comment thread apps/web/src/lib/query/docs-prefetch.ts Resolved
Validate the doc list filter with docFilterSchema at the route boundary,
fold the doc id into the hash-scroll readiness token so a switch between
docs that share a heading id still scrolls, clear the unsaved marker when
the doc pane unmounts, and only swallow a not-found detail prefetch while
rethrowing every other failure.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

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