Skip to content

fix(pages): Features nav scrolls to #features section instead of navigating to / - #537

Closed
Sunil56224972 wants to merge 5 commits into
alibaba:mainfrom
Sunil56224972:fix/features-nav-scroll
Closed

fix(pages): Features nav scrolls to #features section instead of navigating to /#537
Sunil56224972 wants to merge 5 commits into
alibaba:mainfrom
Sunil56224972:fix/features-nav-scroll

Conversation

@Sunil56224972

Copy link
Copy Markdown
Contributor

Summary

Fixes #495

The Features nav tab in the Navbar navigated to / which is identical to clicking the logo ? making it indistinguishable from Home.

Changes

pages/src/components/Navbar.tsx

  • Changed Features path from / to /#features
  • Added handleNavClick callback that handles hash-based navigation:
    • If already on the target page ? smooth-scrolls to the #features anchor
    • If on a different page ? navigates first, then scrolls after render
  • Added useEffect to scroll to hash target after cross-page navigation (with 100ms delay for render)
  • Updated isActive logic: Features tab is highlighted only when currentPath === '/' AND currentHash === '#features' (no longer highlighted just from being on the home page)

pages/src/pages/FeaturesPage.tsx

  • Wrapped HighlightsSection in a <div id="features"> to provide the scroll anchor target

Acceptance Criteria (from #495)

  • Clicking "Features" produces a visually distinct navigation action (smooth scroll to features section)
  • Active tab highlighting correctly reflects the current page (Features only active with hash)
  • All other nav links continue to work as before (unchanged)

Closes alibaba#495

The Features nav tab pointed to '/' which was indistinguishable from
clicking the logo. Change it to '/#features' so it scrolls to the
features section on the landing page.

- Add handleNavClick that splits hash routes and scrolls to the
  target element when already on the correct page
- Add useEffect to scroll to hash target after cross-page navigation
- Update isActive logic to highlight Features only when the hash
  matches
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 5 issue(s) in this PR.

  • ✅ Successfully posted inline: 5 comment(s)

Comment thread pages/src/components/Navbar.tsx Outdated
Comment on lines +12 to +13
{ value: 'zh', label: '中文' },
{ value: 'ja', label: '日本語' },

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.

Character encoding corruption: The Chinese and Japanese labels are stored as mojibake (中文 instead of 中文, 日本語 instead of 日本語). This will render as garbled text in the browser, making the language selector unusable for non-English users. The same issue appears on line 182 for the mobile language button text. Please ensure the file is saved with UTF-8 encoding and re-commit with correct characters.

Comment thread pages/src/components/Navbar.tsx Outdated
Comment on lines +68 to +73
const timer = setTimeout(() => {
const el = document.getElementById(id);
if (el) {
el.scrollIntoView({ behavior: 'smooth' });
}
}, 100);

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.

Fragile hardcoded delay: The 100ms setTimeout is an arbitrary magic number that may not be sufficient on slower devices or pages with heavier rendering. Consider using requestAnimationFrame (possibly double-rAF to wait for paint) or a MutationObserver/ResizeObserver to detect when the target element is actually rendered, rather than relying on a fixed timeout. Also note that this effect runs whenever currentPath changes even if currentHash hasn't changed, which could cause unnecessary scroll attempts.

Comment thread pages/src/components/Navbar.tsx Outdated
fontFamily: language === 'ja' ? "'Hiragino Sans', sans-serif" : "'PingFang SC', -apple-system, sans-serif",
}}>
{language === 'en' ? 'En' : language === 'zh' ? '' : ''}
{language === 'en' ? 'En' : language === 'zh' ? '中' : 'あ'}

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.

Nested ternary expression: This violates the code quality rule prohibiting nested ternaries. Consider using a lookup object for better readability and maintainability:

const LANG_ABBREVIATIONS: Record<Language, string> = { en: 'En', zh: '中', ja: 'あ' };

Then use {LANG_ABBREVIATIONS[language]} here.

Comment on lines +18 to +20
<div id="features">
<HighlightsSection />
</div>

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 race condition with ScrollToTop: When navigating from another page (e.g., /benchmark) to /#features, the ScrollToTop component in App.tsx will first scroll the window to top (triggered by pathname change to /). Then this useEffect fires after a 100ms delay to scroll to the #features element. This causes a visible double-scroll effect (jump to top, then smooth scroll down).

Consider either:

  1. Making ScrollToTop skip scrolling when there's a hash present, or
  2. Increasing the delay / using requestAnimationFrame to ensure the scroll-to-top has completed before scrolling to the anchor, or
  3. Using an immediate (non-smooth) scroll in this useEffect to avoid the visual glitch.

Comment on lines +18 to +20
<div id="features">
<HighlightsSection />
</div>

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.

UX regression: No active tab on root path /: Previously, the Features tab had path: '/' and was marked active whenever currentPath === '/'. Now it requires both currentPath === '/' AND currentHash === '#features'. This means when a user visits / directly (without the hash), no nav tab will be highlighted as active.

Consider falling back to treating / without a hash as the features tab being active, e.g.:

const isActive = tab.path === '/#features'
  ? currentPath === '/' && (currentHash === '#features' || currentHash === '')
  : currentPath.startsWith(tab.path);

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Character encoding corruption

- Fix UTF-8 encoding corruption (mojibake in CJK labels)
- Replace fragile 100ms setTimeout with double-rAF
- Extract nested ternary into LANG_ABBREVIATIONS lookup
- Fix useEffect to depend only on currentHash (not currentPath)
- Fall back to Features tab active on '/' without hash
Prevents double-scroll effect (jump-to-top then smooth-scroll-down)
when navigating from another page to /#features.
@Sunil56224972

Copy link
Copy Markdown
Contributor Author

Addressed all 5 review comments. Here's what changed:

1. Encoding corruption — Rebuilt all files from upstream UTF-8 source. CJK characters are now correct.

2. Fragile 100ms setTimeout — Replaced with double requestAnimationFrame (waits for actual browser paint, no magic numbers).

3. Nested ternary — Extracted into a LANG_ABBREVIATIONS lookup object.

4. ScrollToTop race condition — Updated ScrollToTop in App.tsx to skip scrollTo(0,0) when a hash is present, preventing the double-scroll visual glitch.

5. No active tab on / — Features tab now falls back to active when currentHash === '' (i.e., visiting / without a hash).

Files changed:

  • pages/src/components/Navbar.tsx — fixes 1, 2, 3, 5
  • pages/src/App.tsx — fix 4 (ScrollToTop hash-aware)
  • pages/src/pages/FeaturesPage.tsx — unchanged (re-pushed from clean upstream encoding)

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! Unfortunately, this change has become outdated — we've already merged an earlier PR that addresses the same issue.

We appreciate the effort and would love to see you contribute again in the future. Feel free to pick up any open issues or propose new improvements!

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.

fix(pages): Features nav link navigates to "/" making it indistinguishable from Home

2 participants