Skip to content

Conversation

@tomusdrw
Copy link
Member

@tomusdrw tomusdrw commented May 5, 2025

Also fixes #197

@tomusdrw tomusdrw requested review from DrEverr and mateuszsikora May 5, 2025 23:02
@coderabbitai
Copy link

coderabbitai bot commented May 5, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes introduce support for search and section parameters in the location state, refactor URL hash parsing/serialization, and improve version handling in the location provider. Components such as Search, Outline, Sidebar, and Tabs are updated to coordinate search completion with outline navigation. The Tabs component now supports always rendering all tab contents with CSS-based visibility.

Changes

File(s) Change Summary
src/components/LocationProvider/LocationProvider.tsx Extended ILocationParams with optional search and section; made version optional; refactored hash parsing/serialization; improved version handling; added helpers for parsing/serializing hash.
src/components/NoteManager/NoteManager.tsx Changed note creation to use locationParams.fullVersion instead of locationParams.version.
src/components/Outline/Outline.tsx Added searchIsDone prop; consumed LocationContext; added effect to scroll to outline section after search completion.
src/components/Search/Search.tsx Changed API to use onSearchFinished callback; internalized query state; initialized from location context; updated search completion signaling.
src/components/Sidebar/Sidebar.tsx Removed persistent search query state; added searchIsDone state; coordinated search completion with outline; updated tab rendering logic.
src/components/Tabs/Tabs.css Added .tabs .hidden rule to hide inactive tab content using CSS.
src/components/Tabs/Tabs.tsx Added alwaysRender prop to render all tab contents and toggle visibility with CSS; updated prop types and rendering logic; imported React explicitly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Sidebar
    participant Search
    participant Outline
    participant LocationProvider

    User->>Sidebar: Selects Search Tab
    Sidebar->>Search: Renders Search (with onSearchFinished)
    Search->>LocationProvider: Reads search param from context
    Search->>Search: Performs search
    Search->>Sidebar: Calls onSearchFinished
    Sidebar->>Outline: Sets searchIsDone = true
    Outline->>LocationProvider: Reads section param from context
    Outline->>Outline: Scrolls to section if searchIsDone and section present
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix version switching so that selecting a version does not automatically revert to the latest one (#197)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link

netlify bot commented May 5, 2025

Deploy Preview for graypaper-reader ready!

Name Link
🔨 Latest commit 3bfe990
🔍 Latest deploy log https://app.netlify.com/sites/graypaper-reader/deploys/6819ba008722690008ad9fbc
😎 Deploy Preview https://deploy-preview-236--graypaper-reader.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@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: 3

🔭 Outside diff range comments (1)
src/components/Tabs/Tabs.tsx (1)

29-49: ⚠️ Potential issue

Guard against an invalid activeTab value

activeTabIdx is -1 when the supplied activeTab string does not exist in tabs.
Accessing tabs[-1] below (tabs[activeTabIdx].render()) throws at runtime, breaking the whole UI.

-const activeTabIdx = tabs.map((t) => t.name).indexOf(activeTab);
+const activeTabIdx = tabs.findIndex((t) => t.name === activeTab);
+const safeIdx = activeTabIdx === -1 ? 0 : activeTabIdx; // fallback to first tab

and replace the two usages of activeTabIdx inside the JSX with safeIdx.

This prevents uncaught exceptions while still showing some content to the user.

🧹 Nitpick comments (5)
src/components/Outline/Outline.tsx (1)

20-43: Good implementation of section navigation with some improvement opportunities

The section navigation implementation uses a smart approach with recursive searching through the outline tree and coordinating with search completion.

A few suggestions to make this more robust:

  1. Consider adding some visual feedback when a section is not found
  2. The current implementation uses includes() for matching, which might match unintended sections if they share common text. Consider more precise matching or prioritizing exact matches.
  3. Add a check to ensure the outline is loaded before attempting to find items
  // scroll to section
  const section = locationParams.section?.toLowerCase();
  useEffect(() => {
    if (section === undefined || searchIsDone === false) {
      return;
    }
+   if (outline.length === 0) {
+     return; // Wait until outline is loaded
+   }
    const findItem = (outline: TOutline): TOutline[0] | undefined => {
      for (const item of outline) {
-       if (item.title.toLowerCase().includes(section)) {
+       // Try exact match first, fall back to includes
+       if (item.title.toLowerCase() === section) {
          return item;
+       }
+       
+       // Fall back to partial match if no exact match found
+       if (item.title.toLowerCase().includes(section)) {
+         return item;
        }
        const res = findItem(item.items);
        if (res !== undefined) {
          return res;
        }
      }
      return undefined;
    };

    const itemToScrollTo = findItem(outline);
    if (itemToScrollTo?.dest) {
      linkService?.goToDestination(itemToScrollTo.dest);
+   } else if (section) {
+     // Optionally provide feedback that section wasn't found
+     console.warn(`Section "${section}" not found in outline`);
    }
  }, [searchIsDone, section, outline, linkService]);
src/components/Tabs/Tabs.tsx (1)

33-38: Unnecessary Fragment wrapper

Each iteration already returns a single root <div>; the surrounding React.Fragment adds one extra element to the reconciliation tree without any benefit. Removing it simplifies the DOM.

-<React.Fragment key={tab.name}>
-  <div …>{tab.render()}</div>
-</React.Fragment>
+<div key={tab.name} …>{tab.render()}</div>
src/components/Search/Search.tsx (1)

100-105: Filtering condition is redundant and slightly misleading

x is a tuple [pageIndex, matchesArray], whose length is always 2.
Checking x.length > 0 therefore adds no value and may confuse readers.

-  .filter((x) => x.length > 0 && x[1].length > 0)
+  .filter(([, matches]) => matches.length > 0)
src/components/LocationProvider/LocationProvider.tsx (2)

65-72: Re-serialising the hash drops search/section permanently

handleSetLocationParams intentionally omits search and section from the URL.
However, when invoked from handleHashChange (lines 80-86) in response to an incomplete hash, this causes:

  1. the browser to immediately rewrite the hash without those parameters;
  2. a second hashchange event that no longer exposes the original search/section, making them unrecoverable on page reload or share.

Ensure that the first rewrite honours the original query parameters to keep the page state shareable.


213-218: Header comment mismatches implementation

The comment says “skip the leading ‘/’”, but the code actually removes the leading ‘#’.
Minor, yet worth fixing to avoid confusion for future maintainers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a4d4a8 and ba0b62a.

📒 Files selected for processing (7)
  • src/components/LocationProvider/LocationProvider.tsx (5 hunks)
  • src/components/NoteManager/NoteManager.tsx (1 hunks)
  • src/components/Outline/Outline.tsx (1 hunks)
  • src/components/Search/Search.tsx (5 hunks)
  • src/components/Sidebar/Sidebar.tsx (2 hunks)
  • src/components/Tabs/Tabs.css (1 hunks)
  • src/components/Tabs/Tabs.tsx (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/Sidebar/Sidebar.tsx (3)
src/components/Outline/Outline.tsx (1)
  • Outline (10-61)
src/components/Search/Search.tsx (1)
  • Search (7-33)
src/components/Tabs/Tabs.tsx (1)
  • Tabs (18-50)
🪛 GitHub Check: build
src/components/NoteManager/NoteManager.tsx

[failure] 58-58:
Property 'fullVersion' does not exist on type 'ILocationParams'.

🔇 Additional comments (7)
src/components/Tabs/Tabs.css (1)

39-41: Good addition to support the new alwaysRender prop!

This CSS rule elegantly implements the hiding mechanism for inactive tabs when the new alwaysRender prop is used. The rule completely removes hidden elements from the layout flow, which ensures inactive tabs don't affect the UI while still preserving their state in the DOM.

src/components/Outline/Outline.tsx (1)

10-12: Good implementation of the searchIsDone prop and LocationContext integration

Adding the searchIsDone prop and integrating with LocationContext makes the component properly aware of both search state and location parameters, which is essential for the section navigation feature.

src/components/Sidebar/Sidebar.tsx (4)

33-39: Well-implemented search completion state tracking

Good use of state and callbacks to track search completion status. The comments clearly explain the purpose of this state, and the useCallback is appropriately used to memoize the callback function.


43-43: Good implementation of passing searchIsDone to Outline

Properly connects the search completion state to the Outline component, enabling section navigation after search completes.


51-51: Good implementation of passing onSearchFinished to Search

Properly provides the callback to the Search component, allowing it to signal when search is complete.


59-59: Great use of alwaysRender prop to maintain component state

Using the alwaysRender prop for Tabs is essential for this feature to work properly. This ensures that the Outline component stays mounted and can respond to search completion events, even when it's not the active tab.

src/components/LocationProvider/LocationProvider.tsx (1)

48-53: Possible undefined in versionName

metadata.versions[fullVersion]?.name can be undefined when the hash contains an unknown commit.
serializeSearchParams would then place v=undefined in the URL, which pollutes history and breaks deep-links.

Consider a fallback:

-const versionName = fullVersion ? metadata.versions[fullVersion]?.name : …
+const versionName =
+  fullVersion && metadata.versions[fullVersion]
+    ? metadata.versions[fullVersion].name
+    : metadata.versions[metadata.latest]?.name;

@mateuszsikora mateuszsikora merged commit 54c4cee into main May 6, 2025
8 checks passed
@mateuszsikora mateuszsikora deleted the td-links branch May 6, 2025 08:02
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2025
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.

Version change is not working in a specific case

2 participants