Skip to content

Multi group codesnippets#610

Merged
PaulicStudios merged 3 commits intodevfrom
multi-group-codesnippets
Apr 5, 2026
Merged

Multi group codesnippets#610
PaulicStudios merged 3 commits intodevfrom
multi-group-codesnippets

Conversation

@PaulicStudios
Copy link
Copy Markdown
Member

@PaulicStudios PaulicStudios commented Apr 5, 2026

Summary by CodeRabbit

  • New Features

    • Tabbed code block groups for improved readability and navigation
    • Sidebar scroll position now preserved across page navigations
    • Navigation accordion states saved and restored during browsing
  • Bug Fixes

    • Improved code text wrapping and overflow behavior
    • Tables are now horizontally scrollable for better mobile display

@PaulicStudios PaulicStudios self-assigned this Apr 5, 2026
@PaulicStudios PaulicStudios requested a review from Peu77 April 5, 2026 11:03
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

This pull request enhances wiki page navigation and code display by introducing scroll position persistence for the sidebar, a new scroll-to-heading utility for consistent anchor navigation, client-side tab switching for grouped code blocks via event delegation, accordion state persistence in navigation, and comprehensive CSS styling updates for tabbed code groups and scrollable tables.

Changes

Cohort / File(s) Summary
Wiki Layout & Navigation
frontend/components/wiki/WikiLayout.tsx, frontend/components/wiki/WikiNavigation.tsx
Added sidebar scroll position restoration via sessionStorage with debouncing; replaced scrollIntoView with history.replaceState + scrollToWikiHeading helper for header anchor navigation; implemented client-side DOM event delegation for code group tab switching (click/keyboard interactions); updated accordion rendering to use session-backed controlled state; adjusted layout constraints with fixed heights, overflow-hidden, and internal scrolling via overflow-y-auto.
Markdown Processing
frontend/lib/markdown.ts
Integrated rehype-code-group plugin into the unified markdown→HTML pipeline and added post-processing to strip injected <head> elements from generated HTML.
Scroll Utility
frontend/lib/wiki-scroll.ts
Added new exported function scrollToWikiHeading(element) that smoothly scrolls the .main-wiki-content container to position a target element using getBoundingClientRect() and container-relative offset calculations.
Dependencies & Styling
frontend/package.json, frontend/styles/globals.css, frontend/styles/wiki.css
Added rehype-code-group@^0.3.1 dependency; updated global CSS code wrapping from text-wrap: nowrap to overflow-wrap: break-word; added comprehensive styling for .rehype-code-group tabbed code blocks including tab container layout, tab hover/active/focus states, panel visibility toggling via .active class, and horizontally scrollable table blocks.

Sequence Diagram

sequenceDiagram
    actor User
    participant WikiNav as WikiNavigation
    participant WL as WikiLayout
    participant ScrollUtil as wiki-scroll
    participant DOM as Main Content<br/>(DOM)
    participant Storage as sessionStorage

    User->>WikiNav: Click TOC heading link
    WikiNav->>Storage: Check if hash matches heading
    alt Hash found
        WikiNav->>WikiNav: Set activeId to hash
    else Hash not found
        WikiNav->>WikiNav: Find closest heading to scroll top
    end
    WikiNav->>DOM: history.replaceState(null, "", `#id`)
    WikiNav->>ScrollUtil: scrollToWikiHeading(element)
    ScrollUtil->>DOM: Get .main-wiki-content container
    ScrollUtil->>DOM: Calculate target offset via getBoundingClientRect()
    ScrollUtil->>DOM: container.scrollTo({ top, behavior: "smooth" })
    
    User->>WL: Scroll sidebar
    WL->>WL: Debounce scroll event
    WL->>Storage: Save sidebar.scrollTop
    
    User->>WL: Reload/navigate back
    WL->>Storage: Read sidebar scroll position
    WL->>DOM: Apply scrollTop in useLayoutEffect
    DOM->>User: Sidebar restored to previous position
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • core-team/website#470: Modifies the same wiki layout and navigation components (WikiLayout.tsx, WikiNavigation.tsx), affecting anchor scrolling behavior and sidebar styling, indicating concurrent or overlapping work on wiki scroll functionality.

Poem

🐰 Hops through headings with a scroll, no need to fumble or stroll,
Tab-grouped code now dances right, tabs switch smooth without a fight,
Session remembers where we were, sidebar stays put, no blur,
Break-word wrapping makes prose neat, wiki improvement, quite the feat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Multi group codesnippets' directly corresponds to the main changes: adding grouped code-block support via rehype-code-group, implementing tab switching for .rehype-code-group code groups, and adding related styling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch multi-group-codesnippets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
frontend/components/wiki/WikiNavigation.tsx (1)

255-257: ⚠️ Potential issue | 🟡 Minor

Keep the current branch expanded.

If closedAccordions already contains a parent directory, this collapses it even when currentPath points to a descendant page. The active page and its TOC then stay hidden inside a closed section after direct/search navigation.

🔧 Suggested fix
     const itemPath = item.slug.join("/");
     const uniqueKey = `${itemPath}-${depth}-${index}-${item.isFile ? "file" : "dir"}`;
     const isActive = currentPath === itemPath;
+    const isInCurrentBranch
+      = currentPath === itemPath || currentPath.startsWith(`${itemPath}/`);
@@
         <Accordion
           key={uniqueKey}
           type="single"
           collapsible
-          value={closedAccordions.has(itemPath) ? "" : itemPath}
+          value={isInCurrentBranch || !closedAccordions.has(itemPath) ? itemPath : ""}
           onValueChange={val => handleAccordionChange(itemPath, val)}
           className="px-0"
         >

Also applies to: 317-318

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/components/wiki/WikiNavigation.tsx` around lines 255 - 257, The code
collapses parent directories even when the active page is a descendant; update
the collapse logic in WikiNavigation so that a directory with uniqueKey present
in closedAccordions stays expanded if currentPath equals itemPath or is a
descendant (e.g., currentPath.startsWith(itemPath + "/")). Locate where
itemPath, uniqueKey and isActive are computed and change the check that reads
closedAccordions.has(uniqueKey) to also test for ancestry (only for directories)
— treat the accordion as "open" when isActive || currentPath.startsWith(itemPath
+ "/") so descendant pages keep their parent branch expanded (apply the same fix
to the similar logic around the other occurrence at the later block).
frontend/components/wiki/WikiLayout.tsx (1)

88-111: ⚠️ Potential issue | 🟠 Major

Delegate heading-anchor clicks from .main-wiki-content using event delegation.

The effect snapshots the current a.heading-anchor nodes at mount with an empty dependency array. When {children} re-renders during client-side wiki navigation, new heading anchors on the next page won't have this handler attached, falling back to native anchor scrolling instead of the custom scrollToWikiHeading behavior.

This follows the same delegation pattern already used in the code-group (lines 116–198) and wiki-links (lines 200–237) handlers.

🔧 Suggested fix
   useEffect(() => {
     const container = document.querySelector(".main-wiki-content");
     if (!container)
       return;
 
-    const links = container.querySelectorAll("a.heading-anchor");
-    const handleClick = (e: Event) => {
-      e.preventDefault();
-      const href = (e.currentTarget as HTMLAnchorElement).getAttribute("href");
+    const handleClick = (e: MouseEvent) => {
+      const link = (e.target as HTMLElement | null)?.closest("a.heading-anchor") as HTMLAnchorElement | null;
+      if (!link)
+        return;
+
+      e.preventDefault();
+      const href = link.getAttribute("href");
       const targetId = href?.startsWith("#") ? href.slice(1) : null;
       if (targetId) {
         history.replaceState(null, "", `#${targetId}`);
         const target = document.getElementById(targetId);
         if (target) {
           scrollToWikiHeading(target);
         }
       }
     };
 
-    links.forEach(link => link.addEventListener("click", handleClick));
+    container.addEventListener("click", handleClick as EventListener);
     return () => {
-      links.forEach(link => link.removeEventListener("click", handleClick));
+      container.removeEventListener("click", handleClick as EventListener);
     };
   }, []);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/components/wiki/WikiLayout.tsx` around lines 88 - 111, The current
useEffect in WikiLayout.tsx attaches click listeners to a static NodeList of
a.heading-anchor elements at mount, so newly rendered anchors after client-side
navigation won't get handlers; change this to use event delegation by adding a
single click listener on the container
(document.querySelector(".main-wiki-content")) that checks event.target (or
closest("a.heading-anchor")) to find an anchor, prevents default, extracts the
href/targetId, calls history.replaceState and then invokes scrollToWikiHeading
for the resolved element; ensure you remove the delegated listener in the
cleanup and keep the empty dependency array as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/styles/wiki.css`:
- Around line 229-230: Remove the deprecated declaration and fix spacing: delete
the `word-break: break-word;` line and instead ensure a supported rule is
present (e.g., use `overflow-wrap: anywhere;` or keep `overflow-wrap:
break-word;` if intentional) in the same rule block, and add the required blank
line before each of the rule blocks that were added (the blocks containing the
declarations at the locations that held `overflow-wrap`/`word-break` — update
the rule blocks where `overflow-wrap` is set and the other two new blocks
referenced) so the file conforms to the repo's blank-line style.

---

Outside diff comments:
In `@frontend/components/wiki/WikiLayout.tsx`:
- Around line 88-111: The current useEffect in WikiLayout.tsx attaches click
listeners to a static NodeList of a.heading-anchor elements at mount, so newly
rendered anchors after client-side navigation won't get handlers; change this to
use event delegation by adding a single click listener on the container
(document.querySelector(".main-wiki-content")) that checks event.target (or
closest("a.heading-anchor")) to find an anchor, prevents default, extracts the
href/targetId, calls history.replaceState and then invokes scrollToWikiHeading
for the resolved element; ensure you remove the delegated listener in the
cleanup and keep the empty dependency array as before.

In `@frontend/components/wiki/WikiNavigation.tsx`:
- Around line 255-257: The code collapses parent directories even when the
active page is a descendant; update the collapse logic in WikiNavigation so that
a directory with uniqueKey present in closedAccordions stays expanded if
currentPath equals itemPath or is a descendant (e.g.,
currentPath.startsWith(itemPath + "/")). Locate where itemPath, uniqueKey and
isActive are computed and change the check that reads
closedAccordions.has(uniqueKey) to also test for ancestry (only for directories)
— treat the accordion as "open" when isActive || currentPath.startsWith(itemPath
+ "/") so descendant pages keep their parent branch expanded (apply the same fix
to the similar logic around the other occurrence at the later block).
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 59af2898-51dd-46e1-b2a5-4f43b4a56cbf

📥 Commits

Reviewing files that changed from the base of the PR and between d821193 and aee73db.

⛔ Files ignored due to path filters (1)
  • frontend/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • frontend/components/wiki/WikiLayout.tsx
  • frontend/components/wiki/WikiNavigation.tsx
  • frontend/lib/markdown.ts
  • frontend/lib/wiki-scroll.ts
  • frontend/package.json
  • frontend/styles/globals.css
  • frontend/styles/wiki.css

Comment thread frontend/styles/wiki.css
Comment on lines +229 to +230
overflow-wrap: break-word;
word-break: break-word;
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.

⚠️ Potential issue | 🟡 Minor

Clear the stylelint failures in these new declarations.

This hunk currently fails stylelint: Line 230 uses deprecated word-break: break-word, and the added declarations at Lines 229, 276, and 293 are missing the blank line the repo enforces.

💡 Minimal fix
@@
 .wiki-content {
   `@apply` text-foreground;
+
   overflow-wrap: break-word;
-  word-break: break-word;
 }
@@
 .wiki-content code {
   `@apply` px-2 py-1 rounded text-sm font-mono;
+
   overflow-wrap: break-word;
 }
@@
 .wiki-content table {
   `@apply` w-full border-collapse border mb-4;
+
   display: block;
   overflow-x: auto;
 }

Also applies to: 276-276, 293-294

🧰 Tools
🪛 Stylelint (17.6.0)

[error] 229-229: Expected empty line before declaration (declaration-empty-line-before)

(declaration-empty-line-before)


[error] 230-230: Unexpected deprecated keyword "break-word" for property "word-break" (declaration-property-value-keyword-no-deprecated)

(declaration-property-value-keyword-no-deprecated)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/styles/wiki.css` around lines 229 - 230, Remove the deprecated
declaration and fix spacing: delete the `word-break: break-word;` line and
instead ensure a supported rule is present (e.g., use `overflow-wrap: anywhere;`
or keep `overflow-wrap: break-word;` if intentional) in the same rule block, and
add the required blank line before each of the rule blocks that were added (the
blocks containing the declarations at the locations that held
`overflow-wrap`/`word-break` — update the rule blocks where `overflow-wrap` is
set and the other two new blocks referenced) so the file conforms to the repo's
blank-line style.

@PaulicStudios PaulicStudios merged commit 31669d4 into dev Apr 5, 2026
4 checks passed
@PaulicStudios PaulicStudios deleted the multi-group-codesnippets branch April 5, 2026 21:03
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.

wiki content sidebar always jumps to top when you navigate to other content

1 participant