Skip to content

feat: smooth scroll to id in module page#4451

Open
TheMythologist wants to merge 2 commits into
masterfrom
smooth-scroll-to-fragment
Open

feat: smooth scroll to id in module page#4451
TheMythologist wants to merge 2 commits into
masterfrom
smooth-scroll-to-fragment

Conversation

@TheMythologist

Copy link
Copy Markdown
Contributor

No description provided.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
nusmods-export Ignored Ignored Preview Jul 10, 2026 12:12am
nusmods-website Ignored Ignored Preview Jul 10, 2026 12:12am

Request Review

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR scopes smooth scrolling for module pages to the component lifecycle. The main changes are:

  • Adds a React effect in ModulePageContent to set smooth scrolling on the document root.
  • Cleans up the document-root scroll behavior when the module page unmounts.
  • Skips the smooth-scroll setup when reduced motion is already enabled.

Confidence Score: 4/5

This is close, but the reduced-motion handling should be fixed before merging.

  • Smooth scrolling is now scoped to the module page lifecycle.
  • Reduced motion is only checked at mount time.
  • Users who enable reduced motion while the page is open can still see animated side-menu scrolling.

website/src/views/modules/ModulePageContent.tsx

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
website/src/views/modules/ModulePageContent.tsx:78-85
**Reduced motion can persist** This samples `prefers-reduced-motion` only when the module page mounts. If a user opens the page with reduced motion off, then enables reduced motion while staying on the same module page, `html.style.scrollBehavior` remains `smooth` until unmount. Later side-menu hash clicks can still animate even after the user has requested reduced motion.

Reviews (2): Last reviewed commit: "fix(modules): scope smooth scroll to pag..." | Re-trigger Greptile

Comment thread website/src/views/modules/ModulePageContent.scss Outdated
Comment on lines +3 to +5
html {
scroll-behavior: smooth;
}

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.

P1 Reduced Motion Still Animates

This sets smooth scrolling unconditionally on html. Users with prefers-reduced-motion: reduce will still get animated hash navigation and default scrollIntoView() movement, which regresses the previous instant-scroll behavior for that accessibility setting.

Suggested change
html {
scroll-behavior: smooth;
}
@media (prefers-reduced-motion: no-preference) {
html {
scroll-behavior: smooth;
}
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: website/src/views/modules/ModulePageContent.scss
Line: 3-5

Comment:
**Reduced Motion Still Animates**

This sets smooth scrolling unconditionally on `html`. Users with `prefers-reduced-motion: reduce` will still get animated hash navigation and default `scrollIntoView()` movement, which regresses the previous instant-scroll behavior for that accessibility setting.

```suggestion
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}
```

How can I resolve this? If you propose a fix, please make it concise.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.46%. Comparing base (988c6fd) to head (c5f15d4).
⚠️ Report is 264 commits behind head on master.

Files with missing lines Patch % Lines
website/src/views/modules/ModulePageContent.tsx 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4451      +/-   ##
==========================================
+ Coverage   54.52%   58.46%   +3.93%     
==========================================
  Files         274      316      +42     
  Lines        6076     7300    +1224     
  Branches     1455     1795     +340     
==========================================
+ Hits         3313     4268     +955     
- Misses       2763     3032     +269     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The `html { scroll-behavior: smooth }` rule in the module page stylesheet
was a global element selector, so it leaked to every route once the chunk
loaded and ignored `prefers-reduced-motion`.

Scope the behavior to the module page's lifecycle in JS instead, gated on
`prefers-reduced-motion: no-preference`, and drop the global CSS rule.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment on lines +78 to +85
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return undefined;

const { style } = document.documentElement;
style.scrollBehavior = 'smooth';
return () => {
style.scrollBehavior = '';
};
}, []);

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.

P1 Reduced motion can persist This samples prefers-reduced-motion only when the module page mounts. If a user opens the page with reduced motion off, then enables reduced motion while staying on the same module page, html.style.scrollBehavior remains smooth until unmount. Later side-menu hash clicks can still animate even after the user has requested reduced motion.

Prompt To Fix With AI
This is a comment left during a code review.
Path: website/src/views/modules/ModulePageContent.tsx
Line: 78-85

Comment:
**Reduced motion can persist** This samples `prefers-reduced-motion` only when the module page mounts. If a user opens the page with reduced motion off, then enables reduced motion while staying on the same module page, `html.style.scrollBehavior` remains `smooth` until unmount. Later side-menu hash clicks can still animate even after the user has requested reduced motion.

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant