Skip to content

feat(landing): improve navigation between pages with hash routing and…#29

Merged
rafia9005 merged 1 commit into
terarush:devfrom
szmaou:dev
Jun 22, 2026
Merged

feat(landing): improve navigation between pages with hash routing and…#29
rafia9005 merged 1 commit into
terarush:devfrom
szmaou:dev

Conversation

@szmaou

@szmaou szmaou commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

… scroll handling

  • Fix AppNavbar anchor navigation to detect current route before scrolling — when on a non-landing page (e.g. /contributing), navigate to the landing page with the hash first instead of trying to find non-existent DOM elements
  • Add scroll-to-hash handler in LandingPage onMount so that navigating from another page with a hash (e.g. /#hero) smoothly scrolls to the target section after the page renders
  • Add scrollBehavior to vue-router to automatically scroll to top on every page navigation, handle hash-based scrolling, and restore scroll position on browser back/forward

Summary by CodeRabbit

  • New Features
    • Improved hash link navigation with smooth scrolling to page sections
    • Enhanced browser back/forward navigation to preserve and restore scroll position
    • Better anchor link handling with smooth scroll transitions throughout the app

… scroll handling

- Fix AppNavbar anchor navigation to detect current route before
  scrolling — when on a non-landing page (e.g. /contributing), navigate
  to the landing page with the hash first instead of trying to find
  non-existent DOM elements
- Add scroll-to-hash handler in LandingPage onMount so that navigating
  from another page with a hash (e.g. /#hero) smoothly scrolls to the
  target section after the page renders
- Add scrollBehavior to vue-router to automatically scroll to top on
  every page navigation, handle hash-based scrolling, and restore
  scroll position on browser back/forward
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Hash-based smooth scrolling is added across three files: router/index.ts gains a scrollBehavior function, LandingPage.vue adds an onMounted hook that scrolls to a hash target after a 100ms delay, and AppNavbar.vue updates navigateTo to scroll directly when already on / or navigate with the hash otherwise.

Changes

Hash-based smooth scrolling

Layer / File(s) Summary
Router scrollBehavior and LandingPage mount hook
landing/src/router/index.ts, landing/src/views/LandingPage.vue
scrollBehavior is added to the router to handle hash targets, saved positions, and top-of-page defaults. LandingPage adds onMounted with a 100ms delay to scroll the matching DOM element into view when route.hash is set on initial load.
AppNavbar route-aware hash navigation
landing/src/components/AppNavbar.vue
navigateTo now checks route.path: on / it scrolls to the element directly; on other routes it calls router.push with the hash. IntersectionObserver callback and rootMargin are reformatted with no functional change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop, hop, the anchor calls,
A hash in the URL, the page smoothly falls,
On / I scroll, off / I leap,
A 100ms pause so the DOM won't sleep,
Smooth scrolling for all — now isn't that neat! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is incomplete and cuts off mid-sentence with 'and…', making it vague and not fully descriptive of the actual changes. Complete the title to clearly summarize the main change, such as: 'feat(landing): improve navigation with hash routing and scroll behavior' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
landing/src/views/LandingPage.vue (1)

15-23: ⚡ Quick win

Replace magic timeout with DOM-ready mechanism.

The 100ms timeout is arbitrary and may be unreliable—too short on slower devices where rendering might take longer, or unnecessarily long on fast devices. Consider using nextTick or requestAnimationFrame to ensure the DOM is ready, or implement a retry mechanism that checks for element existence.

♻️ Alternative approach using nextTick
+import { onMounted, nextTick } from 'vue'
-import { onMounted } from 'vue'
 import { useRoute } from 'vue-router'
 
 const route = useRoute()
 
 onMounted(() => {
   if (route.hash) {
     const id = route.hash.slice(1)
-    setTimeout(() => {
+    nextTick(() => {
       const el = document.getElementById(id)
       if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' })
-    }, 100)
+    })
   }
 })

Note: If nextTick proves insufficient, consider a polling approach that checks for element existence with a maximum retry limit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@landing/src/views/LandingPage.vue` around lines 15 - 23, The arbitrary 100ms
setTimeout in the onMounted hook is unreliable across different device speeds
and may cause the element scroll to fail if rendering takes longer. Replace the
setTimeout approach with Vue's nextTick function, which guarantees the DOM is
ready before executing the scroll logic. Import nextTick from Vue at the top of
the file, then wrap the document.getElementById and scrollIntoView logic inside
a nextTick callback instead of using the hardcoded timeout. This ensures the
element lookup and smooth scroll behavior execute once the DOM updates are
complete.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@landing/src/router/index.ts`:
- Around line 19-27: The scrollBehavior function in the router and the onMounted
hook in LandingPage.vue are both attempting to scroll to hash targets, causing
duplicate scroll operations. To fix this, remove the hash handling logic from
the scrollBehavior function (the condition checking to.hash and returning { el:
to.hash, behavior: 'smooth' }) and let the onMounted hook in LandingPage.vue
handle all scrolling to hash elements. This ensures a single, consistent scroll
mechanism at the component level with proper DOM-ready timing, eliminating race
conditions and jarring double-scroll behavior.

---

Nitpick comments:
In `@landing/src/views/LandingPage.vue`:
- Around line 15-23: The arbitrary 100ms setTimeout in the onMounted hook is
unreliable across different device speeds and may cause the element scroll to
fail if rendering takes longer. Replace the setTimeout approach with Vue's
nextTick function, which guarantees the DOM is ready before executing the scroll
logic. Import nextTick from Vue at the top of the file, then wrap the
document.getElementById and scrollIntoView logic inside a nextTick callback
instead of using the hardcoded timeout. This ensures the element lookup and
smooth scroll behavior execute once the DOM updates are complete.
🪄 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: f6a054fd-ae7f-4bf5-8056-ebea93d54c21

📥 Commits

Reviewing files that changed from the base of the PR and between 2adf11c and ce60017.

📒 Files selected for processing (3)
  • landing/src/components/AppNavbar.vue
  • landing/src/router/index.ts
  • landing/src/views/LandingPage.vue

Comment on lines +19 to +27
scrollBehavior(to, _from, savedPosition) {
if (to.hash) {
return { el: to.hash, behavior: 'smooth' }
}
if (savedPosition) {
return savedPosition
}
return { top: 0 }
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Potential duplicate scrolling with LandingPage onMounted hook.

When navigating to the landing page with a hash (e.g., from /contributing to /#hero), both this scrollBehavior function and the onMounted hook in LandingPage.vue (lines 15-23) will attempt to scroll to the same target element. The router's scrollBehavior executes during navigation, then the component's onMounted waits 100ms and scrolls again.

Consider one of these approaches:

  1. Remove hash handling from scrollBehavior and rely solely on the component-level onMounted hook for consistency
  2. Remove the onMounted hook from LandingPage.vue and handle DOM-ready timing in scrollBehavior (though Vue Router provides limited delay options)
  3. Add a flag to coordinate between the two layers to prevent double scrolling

The current implementation may cause jarring double-scroll behavior or race conditions depending on render timing.

Related files: landing/src/views/LandingPage.vue:15-23, landing/src/components/AppNavbar.vue:27-33

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@landing/src/router/index.ts` around lines 19 - 27, The scrollBehavior
function in the router and the onMounted hook in LandingPage.vue are both
attempting to scroll to hash targets, causing duplicate scroll operations. To
fix this, remove the hash handling logic from the scrollBehavior function (the
condition checking to.hash and returning { el: to.hash, behavior: 'smooth' })
and let the onMounted hook in LandingPage.vue handle all scrolling to hash
elements. This ensures a single, consistent scroll mechanism at the component
level with proper DOM-ready timing, eliminating race conditions and jarring
double-scroll behavior.

@rafia9005 rafia9005 merged commit d46bc26 into terarush:dev Jun 22, 2026
3 checks passed
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