Skip to content

fix: should only consider stable original config nav length#297

Merged
JounQin merged 2 commits intomainfrom
fix/unstable_nav
Apr 2, 2026
Merged

fix: should only consider stable original config nav length#297
JounQin merged 2 commits intomainfrom
fix/unstable_nav

Conversation

@JounQin
Copy link
Copy Markdown
Member

@JounQin JounQin commented Apr 2, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Fixed issues in the version navigation so dynamically inserted entries (current version, version groups, download link) render reliably and duplicates are removed.
    • Improved stability of the versions navigation updating logic to reduce intermittent rendering glitches.

Copilot AI review requested due to automatic review settings April 2, 2026 07:57
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 2, 2026

🦋 Changeset detected

Latest commit: 1db824b

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
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 47 seconds.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a781b3a1-84fd-4863-898e-29c2d4600718

📥 Commits

Reviewing files that changed from the base of the PR and between 93cd8e7 and 1db824b.

📒 Files selected for processing (1)
  • .changeset/brown-crabs-fry.md

Walkthrough

Tagged dynamically injected nav entries with an internal _hacked flag, removed the memoized originalConfigNav, and changed the effect that mutates configNav to filter out _hacked items and reset configNav.length. Dependency array updated to configNav, forceRender, and navList.

Changes

Cohort / File(s) Summary
VersionsNav update
packages/doom/src/theme/VersionsNav/index.tsx
Added a HackNavItem/_hacked flag and apply it to dynamically inserted nav entries (download link, current version, version groups). Removed originalConfigNav memo, changed cleanup logic to filter out _hacked items and set configNav.length accordingly. Adjusted effect dependencies to configNav, forceRender, and navList.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰
I hop through lists with nimble cheer,
Tagging tweaks that soon appear.
A _hacked mark where new links bloom,
Cleaned and trimmed to make room.
Tiny paws, a tidy view 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing logic to consider only the stable original config nav length by using a _hacked flag to track and filter dynamically injected nav items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/unstable_nav

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 2, 2026

Open in StackBlitz

yarn add https://pkg.pr.new/@alauda/doom@297.tgz
yarn add https://pkg.pr.new/@alauda/doom-export@297.tgz

commit: 1db824b

Copy link
Copy Markdown
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

Adjusts VersionsNav’s “reset to original nav” behavior by tracking an initial nav length and using it when mutating configNav, aiming to only consider the stable original config nav length.

Changes:

  • Replaces originalConfigNav snapshot with a persisted originLength value.
  • Updates the effect that mutates configNav to reset its length using originLength and updates the dependency list accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/doom/src/theme/VersionsNav/index.tsx Outdated
Comment thread packages/doom/src/theme/VersionsNav/index.tsx Outdated
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
packages/doom/src/theme/VersionsNav/index.tsx (1)

48-48: Potential stale baseline length when nav source changes

originLength at Line 48 is frozen from first render. If nav later changes identity/length (e.g., locale/context switch without remount), Line 141 can apply an outdated length and produce incorrect truncation/expansion before appending navList.

Proposed adjustment (track baseline per configNav instance)
-import { useEffect, useMemo, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
@@
-  const [originLength] = useState(configNav.length)
+  const originLengthRef = useRef(configNav.length)
+
+  useEffect(() => {
+    originLengthRef.current = configNav.length
+  }, [configNav])
@@
-    configNav.length = originLength
+    configNav.length = originLengthRef.current
     configNav.push(...navList)
     forceRender()
-  }, [configNav, forceRender, navList, originLength])
+  }, [configNav, forceRender, navList])

Also applies to: 141-144

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

In `@packages/doom/src/theme/VersionsNav/index.tsx` at line 48, originLength is
captured once via useState and can become stale when configNav/nav changes;
update the baseline whenever configNav identity changes by deriving originLength
from configNav (e.g., compute originLength = configNav.length with useMemo or
update the state inside a useEffect that listens to configNav) so that the
truncation/expansion logic that uses originLength (see originLength, configNav,
nav, navList) always uses the current baseline and avoids incorrect slicing at
the block around lines referencing originLength (the truncation/append logic).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/doom/src/theme/VersionsNav/index.tsx`:
- Line 48: originLength is captured once via useState and can become stale when
configNav/nav changes; update the baseline whenever configNav identity changes
by deriving originLength from configNav (e.g., compute originLength =
configNav.length with useMemo or update the state inside a useEffect that
listens to configNav) so that the truncation/expansion logic that uses
originLength (see originLength, configNav, nav, navList) always uses the current
baseline and avoids incorrect slicing at the block around lines referencing
originLength (the truncation/append logic).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f30b118-9da3-450b-b3d0-f0d739dc1997

📥 Commits

Reviewing files that changed from the base of the PR and between 6ae49b7 and ee3a91b.

📒 Files selected for processing (1)
  • packages/doom/src/theme/VersionsNav/index.tsx

Copy link
Copy Markdown
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/doom/src/theme/VersionsNav/index.tsx
Signed-off-by: JounQin <admin@1stg.me>
Copy link
Copy Markdown
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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JounQin JounQin merged commit 9796a59 into main Apr 2, 2026
18 checks passed
@JounQin JounQin deleted the fix/unstable_nav branch April 2, 2026 08:15
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.

2 participants