Skip to content

Conversation

@JounQin
Copy link
Member

@JounQin JounQin commented Jun 4, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved the stability of heading slugs, ensuring consistent IDs even when children change.
  • Chores
    • Updated internal metadata to reflect a patch addressing slug instability.
  • Performance Improvements
    • Enhanced memoization and dependency management across multiple components for better rendering efficiency.
  • Enhancements
    • Improved document title updates to respond to a wider range of page data changes.
    • Updated version navigation to react to version changes dynamically.
    • Refined external site link and display name updates to reflect prop changes accurately.
  • Developer Experience
    • Added support for the latest React Hooks ESLint plugin.
    • Improved ESLint configuration for better code quality checks.

@JounQin JounQin self-assigned this Jun 4, 2025
Copilot AI review requested due to automatic review settings June 4, 2025 07:29
@JounQin JounQin added the bug Something isn't working label Jun 4, 2025
@changeset-bot
Copy link

changeset-bot bot commented Jun 4, 2025

🦋 Changeset detected

Latest commit: 500fb27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alauda/doom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

Warning

Rate limit exceeded

@JounQin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6e5333b and 500fb27.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • eslint.config.js (2 hunks)
  • package.json (1 hunks)
  • src/global/SiteOverrides/index.tsx (1 hunks)
  • src/global/VersionsNav/index.tsx (1 hunks)
  • src/runtime/components/ExternalSiteLink.tsx (1 hunks)
  • src/runtime/components/K8sCrd.tsx (4 hunks)
  • src/runtime/components/K8sPermissionTable.tsx (1 hunks)
  • src/runtime/components/Mermaid.tsx (1 hunks)
  • src/runtime/components/OpenAPIPath.tsx (1 hunks)
  • src/runtime/components/OpenAPIRef.tsx (2 hunks)
  • src/runtime/components/Overview.tsx (4 hunks)
  • src/runtime/components/_ExternalSiteBase.tsx (1 hunks)
  • src/runtime/components/_HeadingTitle.tsx (1 hunks)
  • src/runtime/hooks/useIsPrint.ts (1 hunks)
  • src/runtime/hooks/useSiteOverrides.ts (1 hunks)

Walkthrough

A changeset file was added to document a patch update for the @alauda/doom package, addressing an unstable slug issue caused by changes in children. The HeadingTitle component's slug computation was refactored to use a memoized value, centralizing and optimizing slug extraction from its children.

Changes

File(s) Change Summary
.changeset/heavy-crews-glow.md Added a changeset documenting a patch update for unstable slug due to children changes.
src/runtime/components/_HeadingTitle.tsx Refactored slug computation by extracting and memoizing logic from children for stable slug usage.

Sequence Diagram(s)

sequenceDiagram
    participant ParentComponent
    participant HeadingTitle

    ParentComponent->>HeadingTitle: Render with children
    HeadingTitle->>HeadingTitle: useMemo to extract slug from children
    HeadingTitle->>HeadingTitle: useMemo to compute id using slug
    HeadingTitle-->>ParentComponent: Rendered heading with stable id
Loading

Possibly related PRs

Poem

A slug once wobbled, wild and free,
Memoized now, as stable as can be.
Children’s words, once scattered wide,
Gathered neatly, side by side.
With every heading, order’s grown—
The rabbits cheer, the bugs have flown! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses an unstable slug issue by refactoring the memoization of the slug used to generate element IDs in the HeadingTitle component.

  • Introduces a memoized value for slug generated from children content.
  • Updates the dependency arrays on useMemo hooks to rely on memoized children slug.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/runtime/components/_HeadingTitle.tsx Refactors slug generation logic using memoized children content.
.changeset/heavy-crews-glow.md Adds a changeset entry documenting the slug fix.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@alauda/doom@58

commit: 500fb27

@JounQin
Copy link
Member Author

JounQin commented Jun 4, 2025

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

✅ Actions performed

Full review triggered.

@JounQin JounQin force-pushed the fix/unstable_slug branch from 89205c8 to 6e5333b Compare June 4, 2025 07:59
@JounQin
Copy link
Member Author

JounQin commented Jun 4, 2025

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Jun 4, 2025

✅ Actions performed

Full review triggered.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a0031a and 6e5333b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (16)
  • .changeset/heavy-crews-glow.md (1 hunks)
  • eslint.config.js (2 hunks)
  • package.json (1 hunks)
  • src/global/SiteOverrides/index.tsx (1 hunks)
  • src/global/VersionsNav/index.tsx (1 hunks)
  • src/runtime/components/ExternalSiteLink.tsx (1 hunks)
  • src/runtime/components/K8sCrd.tsx (4 hunks)
  • src/runtime/components/K8sPermissionTable.tsx (1 hunks)
  • src/runtime/components/Mermaid.tsx (1 hunks)
  • src/runtime/components/OpenAPIPath.tsx (1 hunks)
  • src/runtime/components/OpenAPIRef.tsx (2 hunks)
  • src/runtime/components/Overview.tsx (4 hunks)
  • src/runtime/components/_ExternalSiteBase.tsx (1 hunks)
  • src/runtime/components/_HeadingTitle.tsx (1 hunks)
  • src/runtime/hooks/useIsPrint.ts (1 hunks)
  • src/runtime/hooks/useSiteOverrides.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/runtime/components/_ExternalSiteBase.tsx (1)
src/runtime/hooks/useTranslation.ts (1)
  • useLang (7-7)
🪛 ESLint
src/runtime/components/Overview.tsx

[error] 14-14: Unable to resolve path to module 'react'.

(import-x/no-unresolved)

🔇 Additional comments (28)
src/runtime/hooks/useSiteOverrides.ts (1)

128-128: LGTM! Correctly fixes the dependency array.

The useEffect now properly depends on acpSite and siteData.base, which are both used in the fetchSiteOverrides call. This ensures the effect re-runs when these values change, maintaining correct reactivity.

src/runtime/hooks/useIsPrint.ts (1)

35-35: LGTM! Correctly includes all effect dependencies.

Adding onChange to the dependency array is correct since the effect uses it for event listener registration. This ensures proper cleanup and re-registration if the callback reference changes.

src/global/SiteOverrides/index.tsx (1)

74-81: LGTM! Comprehensive dependency array update.

The expanded dependency array correctly includes all variables used in the effect's logic for computing and setting the document title. This ensures the title updates reactively when any relevant page data changes.

src/runtime/components/_HeadingTitle.tsx (2)

26-32: Excellent refactor! Centralizes slug computation and fixes instability.

Extracting the string content extraction from children into a separate useMemo hook is a smart optimization. This ensures the slug only recalculates when the actual string content changes, not when the children array reference changes but contains the same content.


35-38: LGTM! Proper use of memoized value and correct dependencies.

Using slugFromChildren instead of computing inline eliminates redundant computation and improves stability. The dependency array correctly includes all referenced values: uid, slug, slugger, and slugFromChildren.

.changeset/heavy-crews-glow.md (1)

1-6: Changeset properly documents the fix.

The changeset follows the correct format and accurately describes the patch fix for unstable slug issues.

src/runtime/components/Mermaid.tsx (1)

35-35: Correct dependency array fix.

Adding id to the dependency array is necessary since it's used within the effect to generate the unique mermaid identifier. This ensures the diagram re-renders when the ID changes.

src/global/VersionsNav/index.tsx (1)

109-109: Proper dependency array fix for version fetching.

Adding version and versionsBase to the dependency array is correct since both values are used within the effect. This ensures versions are re-fetched when these inputs change.

package.json (1)

121-121:

Details

✅ Verification successful

Good addition of React hooks ESLint plugin.

Adding eslint-plugin-react-hooks is appropriate given the dependency array fixes in this PR. This will help prevent similar React hooks issues in the future.

Verify this is the latest stable version:


🌐 Web query:

What is the latest stable version of eslint-plugin-react-hooks?

💡 Result:

The latest stable version of eslint-plugin-react-hooks as of June 4, 2025, is 5.2.0. This version was published on February 28, 2025[1][6]. While there is a 6.0.0 release candidate (RC) available, version 5.2.0 is the most recent stable release[6][7].

Citations:


✔️ Approved: eslint-plugin-react-hooks v5.2.0 is up-to-date

The addition of eslint-plugin-react-hooks (v5.2.0) aligns perfectly with the dependency-array fixes in this PR. Version 5.2.0 is confirmed as the latest stable release as of June 4, 2025, so no further changes are needed.

  • package.json (line 121)
src/runtime/components/OpenAPIPath.tsx (1)

200-200: Excellent dependency array fix!

Adding [openapiPath_, page.routePath, path] to the dependency array ensures the memoized OpenAPI path data recalculates correctly when these inputs change. This fixes potential stale closure issues where the component might not update when props change.

src/runtime/components/ExternalSiteLink.tsx (1)

34-37: Correct dependency array fix!

Adding [name] to the dependency array ensures the site lookup recalculates when the name prop changes. This prevents stale closures where the site would remain the same even if a different name prop was passed.

src/runtime/components/_ExternalSiteBase.tsx (2)

97-100: Correct dependency array fix for site lookup.

Adding [name] ensures the site lookup recalculates when the name prop changes, preventing stale memoization.


106-106: Comprehensive dependency array for displayName.

The dependency array [lang, name, site?.displayName] correctly captures all inputs that affect the displayName computation, ensuring proper reactivity when language, name, or site display names change.

eslint.config.js (2)

5-6: LGTM: Proper React hooks plugin integration

The import changes correctly switch to named imports and add React hooks support. This aligns well with the PR's focus on improving React hooks usage patterns.


16-16: LGTM: React hooks linting configuration

Adding the recommended React hooks configuration will help enforce best practices for hooks usage throughout the codebase, which is beneficial given the memoization improvements in this PR.

src/runtime/components/K8sCrd.tsx (3)

75-86: LGTM: Improved JSX formatting for consistent spacing

The explicit spacing fragments ensure consistent visual spacing between elements, improving the component's rendering reliability.


184-184: LGTM: Critical dependency array fix

The useMemo dependency array was previously empty but should include crdPath and name since the memoized computation depends on these props. This fix ensures the component properly recalculates when these props change, which aligns with the PR's goal of fixing unstable behavior.


195-195: LGTM: Consistent formatting improvement

The formatting change maintains consistency with the pattern established in the K8sCrdSchemaPart component.

src/runtime/components/OpenAPIRef.tsx (3)

176-176: LGTM: Essential dependency array correction

The useMemo dependency array was previously empty but should include openapiPath_ and schema since the memoized computation searches for schemas based on these values. This fix ensures proper recalculation when props change.


179-179: LGTM: Improved refs calculation logic

Adding the openapi check ensures refs are only calculated when the OpenAPI document is available, preventing potential errors.


188-191: LGTM: Better error handling flow

Moving the error handling after the refs calculation ensures all memoized values are computed before early returns, improving the component's logic flow.

src/runtime/components/Overview.tsx (7)

14-14: LGTM: Necessary React hooks imports

The addition of useCallback and useMemo imports supports the performance optimizations in this component.

Note: The static analysis error about unresolvable React import appears to be a false positive since React hooks are being used successfully throughout the file.

🧰 Tools
🪛 ESLint

[error] 14-14: Unable to resolve path to module 'react'.

(import-x/no-unresolved)


32-42: LGTM: Function extraction for performance

Moving getChildLink outside the component prevents it from being recreated on every render, which is a good performance optimization since it's a pure function.


60-67: LGTM: Proper memoization of filter function

The subFilter function is correctly memoized with routePath as a dependency, preventing unnecessary re-computations when other props change.


71-74: LGTM: Memoized modules computation

The overviewModules computation is properly memoized with correct dependencies (pages and subFilter), improving performance by avoiding redundant filtering operations.


89-126: LGTM: Complex function properly memoized

The normalizeSidebarItem function is correctly memoized with all relevant dependencies (overviewModules, props.overviewHeaders, routePath). This prevents expensive re-computations while ensuring correctness when dependencies change.


133-184: LGTM: Well-structured memoized group processing

The getGroup function is properly memoized with correct dependencies (frontmatter, normalizeSidebarItem, subFilter). The complex group processing logic is preserved while gaining performance benefits.


186-201: LGTM: Optimized default groups computation

The defaultGroups memoization with fallback logic for nested sidebar groups is well-implemented. The dependencies (getGroup, overviewSidebarGroups) correctly trigger recalculation when needed.

@JounQin JounQin force-pushed the fix/unstable_slug branch from 6e5333b to 500fb27 Compare June 4, 2025 08:16
@JounQin JounQin merged commit 5fc26c4 into 0.x Jun 4, 2025
19 of 20 checks passed
@JounQin JounQin deleted the fix/unstable_slug branch June 4, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants