Repository navigation
feat(docs): rich editor, scroll spy, publish states and doc tree - #40
Conversation
…d doc tree The outline on the right now tracks the section you are reading with a scroll spy, scrolls to keep the active heading in view, and smooth scrolls when an entry is clicked, respecting reduced motion. It used to highlight nothing. Publishing is now two genuinely different states. Anyone with the link is unlisted, noindex, out of the sitemap and revocable by rotating the token. Public on the web is indexable at a readable slug url with Open Graph and JSON-LD, and the old token url keeps working so existing links do not break. The plain textarea is replaced by a real rich editor with a slash command menu, a selection bubble menu, headings, lists, task lists, tables, code blocks with syntax highlighting, images by drag and paste, links, callouts, toggles and mentions. Markdown stays the storage format and the sanitizer stays on the render path. Documents nest in a tree with version history, backlinks and search.
# Conflicts: # apps/web/src/features/docs/doc-editor.tsx # apps/web/src/features/docs/docs.test.ts # packages/core/src/content/doc-service.ts # packages/db/src/schema/content.ts # packages/shared/src/validators/index.ts
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 12 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThe PR adds a Tiptap rich-text editor, document templates, nested document navigation, backlinks, version history and restoration, slugged public URLs, SEO metadata, JSON-LD, sitemap generation, visibility rotation, and expanded end-to-end and unit coverage. ChangesRich editing and document composition
Publishing and persistence
Estimated code review effort: 5 (Critical) | ~120 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…stops leaking across files
…links Replace the up-to-32 sequential ancestor lookups in assertParent with a single WITH RECURSIVE walk that reports the ancestor count and whether the moved doc appears in the chain, preserving the self-nest, cycle, and missing-parent errors. Name the backlink cap so the bound stays explicit; the leading-wildcard ILIKE already rides the doc_content_trgm_idx gin index.
…ping The "Nest under" menu sliced parents to 50 and dropped the rest with no hint. Replace it with a cmdk combobox that filters the already-loaded docs by title, and when matches still exceed the render cap, show a "refine your search" note rather than hiding options silently.
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Actionable comments posted: 7
🧹 Nitpick comments (6)
apps/web/src/features/docs/doc-editor.tsx (1)
190-193: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the shared
tabHoverhelper for the mode segmented control.This rich/markdown switch is a tab-like control but uses raw
transition-colors duration-[var(--duration-fast)]+hover:text-mutedinstead of the shared interaction helper, which drifts from the design-token system.♻️ Suggested change
- className={cn( - 'rounded-sm px-2 py-1 text-2xs transition-colors duration-[var(--duration-fast)]', - mode === option ? 'bg-surface text-text shadow-sm' : 'text-faint hover:text-muted', - )} + className={cn( + 'rounded-sm px-2 py-1 text-2xs', + tabHover, + mode === option ? 'bg-surface text-text shadow-sm' : 'text-faint', + )}Import
tabHoverfrom@/lib/interaction.ts.As per coding guidelines: "use shared interaction tokens for hover and focus transitions", and based on learnings that tab-like controls should use
tabHoverfromapps/web/src/lib/interaction.ts.🤖 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/doc-editor.tsx` around lines 190 - 193, Update the mode segmented control’s className in the doc editor to use the shared tabHover helper for hover and focus interaction styling. Import tabHover from the shared interaction module and replace the raw transition and hover classes, preserving the existing selected-mode classes and layout styling.Sources: Coding guidelines, Learnings
apps/web/src/features/docs/doc-reader.tsx (1)
93-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the shared interaction helpers instead of raw Tailwind color transitions. Both sites implement hover/selected color transitions with ad-hoc
transition-colors/duration-[...]classes rather than the centralized helpers inapps/web/src/lib/interaction.ts, which prior reviews established as the required pattern for these state transitions.
apps/web/src/features/docs/doc-reader.tsx#L93-L115: replacetransition-colors duration-[var(--duration-fast)] hover:text-texton the backlinkLinkwith the appropriate shared helper (e.g.rowHover/surfaceHover).apps/web/src/features/docs/doc-surface.tsx#L263-L357: replace the rawtransition-colors duration-[var(--duration-instant)] ease-[var(--ease-standard)]innestItemClassNamewith the matching shared helper for the selected/highlighted list-item state.🤖 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/doc-reader.tsx` around lines 93 - 115, The backlink Link in apps/web/src/features/docs/doc-reader.tsx#L93-L115 must use the appropriate shared interaction helper from interaction.ts instead of its raw transition-colors, duration, and hover classes. Also update nestItemClassName in apps/web/src/features/docs/doc-surface.tsx#L263-L357 to use the matching shared helper for selected/highlighted list-item transitions, removing the ad-hoc transition classes.Source: Learnings
apps/web/src/app/d/[token]/page.tsx (1)
21-68: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winDeduplicate the published-doc fetch across
generateMetadataand the page.
getPublishedDoc(token)runs once inseoFor(viagenerateMetadata) and again inPublishedDocPage, anddetailForinternally issues author, follower, and backlink queries plussummarize— so every public view doubles that work. WrapgetPublishedDoc(orseoFor) in Reactcache()so the two entry points share a single request-scoped fetch, and reuseseoFor's object for thepublishedDocJsonLdinput instead of rebuilding it inline.🤖 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/d/`[token]/page.tsx around lines 21 - 68, Deduplicate the published document lookup by wrapping getPublishedDoc or seoFor in React cache(), ensuring generateMetadata and PublishedDocPage share one request-scoped result. In PublishedDocPage, reuse the seoFor result when constructing publishedDocJsonLd instead of rebuilding the SEO fields inline, while preserving the existing not-found and redirect behavior.apps/web/src/app/d/sitemap.ts (1)
9-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the shared URL helper instead of building the absolute URL inline.
This reimplements
publicDocUrl(apps/web/src/lib/docs/paths.ts) and hand-builds the origin. Prefer constructing absolute public URLs through the sharedabsoluteUrl(path)/publicAppUrl()helpers inapps/web/src/lib/env.tsso all consumers share one validated, trailing-slash-normalized base.Based on learnings: public application URLs must be built with
publicAppUrl()/absoluteUrl(path)rather than manually concatenatingNEXT_PUBLIC_APP_URLor string-building paths.🤖 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/d/sitemap.ts` around lines 9 - 16, Update the sitemap URL construction in the docs mapping around listPublicDocs and publicDocPath to use the shared absoluteUrl(path) or publicAppUrl() helper instead of serverEnv().NEXT_PUBLIC_APP_URL and new URL. Preserve the existing null-path filtering and lastModified values while ensuring URLs use the shared validated, trailing-slash-normalized base.Source: Learnings
apps/web/src/features/docs/doc-history.tsx (1)
88-88: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a shared hover helper instead of a raw Tailwind class.
hover:bg-surface-2is a raw Tailwind hover class. Based on learnings, hover/focus color transitions in this codebase must go through the shared helpers inapps/web/src/lib/interaction.ts(e.g.rowHover/cardHover/surfaceHover) rather than bespoke Tailwind classes.♻️ Suggested fix
+import { rowHover } from '`@/lib/interaction.ts`'; ... - className="flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-surface-2" + className={cn('flex items-center gap-2 rounded-md px-2 py-1.5', rowHover)}🤖 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/doc-history.tsx` at line 88, Replace the raw hover:bg-surface-2 class on the doc-history element with the appropriate shared hover helper from interaction.ts, such as surfaceHover, while preserving the existing layout and styling classes.Source: Learnings
apps/web/src/lib/query/use-docs.ts (1)
28-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a stricter type for
visibility.
DocShareInput.visibilityis typed as a barestring, losing compile-time protection against invalid values even though the UI only ever passes one of a small fixed set of visibility options (seeVISIBILITY_OPTIONSindoc-share-menu.tsx). A union/enum type here would catch typos at compile time.🤖 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/lib/query/use-docs.ts` around lines 28 - 31, Update DocShareInput.visibility to use a strict union or existing enum derived from the allowed values in VISIBILITY_OPTIONS, preserving compatibility with every valid UI option while rejecting arbitrary strings at compile time.
🤖 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/`[id]/versions/route.ts:
- Around line 11-26: The version-list response unnecessarily includes full
document content. In apps/web/src/app/api/docs/[id]/versions/route.ts lines
11-26, remove content from the mapping in GET; in
apps/web/src/lib/query/schemas.ts lines 255-266, make content optional or use a
summary schema for docVersionListSchema;
apps/web/src/features/docs/doc-history.tsx lines 56-113 requires no direct
change, since VersionList already uses only summary fields.
In `@apps/web/src/app/d/`[token]/page.tsx:
- Around line 70-79: Update the publishedDocJsonLd producer in
published-doc-meta.ts to escape serialized JSON-LD characters before returning
it, at minimum replacing < with \u003c and preferably also >, &, \u2028, and
\u2029. Keep the page’s JSON-LD injection behavior unchanged and revise the
nearby biome-ignore justification to reflect that the serialized output is
safely escaped.
In `@apps/web/src/features/docs/doc-share-menu.tsx`:
- Around line 56-58: Update the URL construction in the doc share menu render to
avoid accessing window.location.origin, which is unsafe during SSR. Reuse the
shared publicDocUrl helper or another server-safe URL base while preserving the
null result when publicDocPath returns null.
In `@apps/web/src/features/docs/doc-tree.tsx`:
- Around line 34-63: Update MAX_TREE_DEPTH used by docTreeOf to match the
backend’s supported nesting limit of 32, ensuring valid documents deeper than
six levels remain visible in the sidebar. Preserve the existing traversal and
cycle-prevention behavior.
In `@apps/web/src/features/docs/outline.ts`:
- Around line 23-28: Update uniqueHeadingId to track and check every emitted ID
globally, not only the counter for the current base. Ensure both the initial
slug and generated suffixed IDs are compared against previously emitted IDs,
incrementing suffixes until an unused ID is found while preserving the existing
used-map contract.
In `@apps/web/src/features/docs/published-doc-meta.ts`:
- Around line 58-72: Update publishedDocJsonLd to make the serialized JSON-LD
safe for script-tag embedding by escaping “<” characters in the JSON string
before returning it, while preserving the existing null behavior and schema
fields. Confirm the consumer uses dangerouslySetInnerHTML if needed, but keep
the required escaping within publishedDocJsonLd for all user-controlled fields.
In `@packages/services/src/markdown/markdown.test.ts`:
- Around line 243-247: Strengthen the test “does not turn a github alert marker
into anything but text” by asserting the literal blockquote HTML structure for
the rendered content, rather than only checking contained text and a blockquote
tag. Also assert that the output does not include alert-specific wrapper
attributes or classes, preserving the plain-text blockquote behavior.
---
Nitpick comments:
In `@apps/web/src/app/d/`[token]/page.tsx:
- Around line 21-68: Deduplicate the published document lookup by wrapping
getPublishedDoc or seoFor in React cache(), ensuring generateMetadata and
PublishedDocPage share one request-scoped result. In PublishedDocPage, reuse the
seoFor result when constructing publishedDocJsonLd instead of rebuilding the SEO
fields inline, while preserving the existing not-found and redirect behavior.
In `@apps/web/src/app/d/sitemap.ts`:
- Around line 9-16: Update the sitemap URL construction in the docs mapping
around listPublicDocs and publicDocPath to use the shared absoluteUrl(path) or
publicAppUrl() helper instead of serverEnv().NEXT_PUBLIC_APP_URL and new URL.
Preserve the existing null-path filtering and lastModified values while ensuring
URLs use the shared validated, trailing-slash-normalized base.
In `@apps/web/src/features/docs/doc-editor.tsx`:
- Around line 190-193: Update the mode segmented control’s className in the doc
editor to use the shared tabHover helper for hover and focus interaction
styling. Import tabHover from the shared interaction module and replace the raw
transition and hover classes, preserving the existing selected-mode classes and
layout styling.
In `@apps/web/src/features/docs/doc-history.tsx`:
- Line 88: Replace the raw hover:bg-surface-2 class on the doc-history element
with the appropriate shared hover helper from interaction.ts, such as
surfaceHover, while preserving the existing layout and styling classes.
In `@apps/web/src/features/docs/doc-reader.tsx`:
- Around line 93-115: The backlink Link in
apps/web/src/features/docs/doc-reader.tsx#L93-L115 must use the appropriate
shared interaction helper from interaction.ts instead of its raw
transition-colors, duration, and hover classes. Also update nestItemClassName in
apps/web/src/features/docs/doc-surface.tsx#L263-L357 to use the matching shared
helper for selected/highlighted list-item transitions, removing the ad-hoc
transition classes.
In `@apps/web/src/lib/query/use-docs.ts`:
- Around line 28-31: Update DocShareInput.visibility to use a strict union or
existing enum derived from the allowed values in VISIBILITY_OPTIONS, preserving
compatibility with every valid UI option while rejecting arbitrary strings at
compile time.
🪄 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: 4a73b839-04fa-4d4f-bc8b-7d0b261c5674
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (45)
apps/web/e2e/docs.spec.tsapps/web/package.jsonapps/web/src/app/(app)/docs/new/page.tsxapps/web/src/app/api/docs/[id]/share/route.tsapps/web/src/app/api/docs/[id]/versions/route.tsapps/web/src/app/d/[token]/page.tsxapps/web/src/app/d/sitemap.tsapps/web/src/components/layout/workspace-switcher.test.tsxapps/web/src/features/comments/comment-composer.test.tsxapps/web/src/features/comments/comment-composer.tsxapps/web/src/features/docs/doc-body.tsxapps/web/src/features/docs/doc-editor.tsxapps/web/src/features/docs/doc-history.tsxapps/web/src/features/docs/doc-outline.tsxapps/web/src/features/docs/doc-reader.test.tsxapps/web/src/features/docs/doc-reader.tsxapps/web/src/features/docs/doc-share-menu.tsxapps/web/src/features/docs/doc-surface.tsxapps/web/src/features/docs/doc-tree.tsxapps/web/src/features/docs/docs-workspace.tsxapps/web/src/features/docs/docs.test.tsapps/web/src/features/docs/editor/commands.tsapps/web/src/features/docs/editor/editor.test.tsapps/web/src/features/docs/editor/extensions.tsapps/web/src/features/docs/editor/markdown.tsapps/web/src/features/docs/editor/rich-text-editor.test.tsxapps/web/src/features/docs/editor/rich-text-editor.tsxapps/web/src/features/docs/editor/styles.tsapps/web/src/features/docs/new-doc.tsxapps/web/src/features/docs/outline.tsapps/web/src/features/docs/published-doc-meta.tsapps/web/src/features/docs/templates.tsapps/web/src/features/docs/use-scroll-spy.tsapps/web/src/features/workspaces/create-workspace-form.test.tsxapps/web/src/lib/docs/paths.tsapps/web/src/lib/query/keys.tsapps/web/src/lib/query/schemas.tsapps/web/src/lib/query/use-docs.tspackages/core/src/content/doc-service.test.tspackages/core/src/content/doc-service.tspackages/db/src/schema/content.tspackages/services/src/markdown/index.tspackages/services/src/markdown/markdown.test.tspackages/services/src/markdown/sanitize.tspackages/shared/src/validators/doc.ts
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Add docs: a rich editor, working scroll spy, real publish states, and a nested doc tree.
Greptile Summary
This PR ships the docs feature end-to-end: a TipTap 3 rich-text editor with slash commands, mentions, and file upload; a working scroll-spy outline; a version history panel with 5-minute coalescing and one-click restore; a nested doc tree with cycle-safe reparenting; and real publish states (workspace / unlisted / public) including slug-based canonical URLs, sitemap generation, JSON-LD, and correct SEO metadata.
editor/) converts between TipTap JSON and markdown on every change; includes Callout, ToggleBlock, TaskList, and Table extensions, with a bubble toolbar and a/slash-command menu./d/<slug>-<token>); token extraction vialastIndexOf('-')is safe becausenewToken()strips all dashes. Unlisted docs getnoindex; public docs get canonical redirect, Open Graph, andArticleJSON-LD.Confidence Score: 4/5
Safe to merge after fixing the toEditorHtml SSR guard — all other paths are solid.
The service layer, publish routing, and version coalescing are well-structured and correct. The one issue worth addressing before merge: toEditorHtml calls document.createElement as an eager argument to useEditor, so the call runs during the server-side render phase. Any first-load of a doc page that starts in edit mode (e.g. the URL a newly created doc redirects to, or a direct deep-link with ?edit=1) would produce a ReferenceError on the server and serve a 500.
apps/web/src/features/docs/editor/extensions.ts — the toEditorHtml function needs an SSR guard before document.createElement.
Important Files Changed
toEditorHtmlwhich usesdocument.createElementwithout an SSR guard.toEditorHtml(called as an eager argument touseEditor).Reviews (3): Last reviewed commit: "feat(docs): make the parent picker searc..." | Re-trigger Greptile
Context used: