Seven minutes after I merged PR #139 — which added the interactive Mountain Study hero to this site’s home pages — Cursor Bugbot left a Medium-severity inline review comment on assets/js/study.js: Header overlay sticks after scrolling.
I asked my AI coding assistant to check the comment. It read the same lines, walked through the W3C specification, agreed that the bug was live on main, and explained in detail how the dark translucent header with ivory text would stay stuck over the light paper sections below. Before touching any code, I asked it to open the live page and show me the failure.
In a real browser, the bug did not happen.
The code and the spec argument
The home page starts with a full-viewport dark study scene. While that scene is visible, the fixed .site-header uses a translucent dark gradient and light ivory text; once the visitor scrolls into the light Codex sections underneath, study.js adds study-scrolled to <body> so the header switches back to its frosted paper surface and dark ink.
In PR #139, the scroll observer looked like this:
if ('IntersectionObserver' in window) {
new IntersectionObserver((entries) => {
document.body.classList.toggle('study-scrolled', !entries[0].isIntersecting);
}, { threshold: 0.15 }).observe(stage);
} else {
const onScroll = () => {
document.body.classList.toggle('study-scrolled', stage.getBoundingClientRect().bottom < 80);
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
On paper, the critique looked airtight. Under a literal geometric reading of the W3C IntersectionObserver specification, entry.isIntersecting reports whether the target and root overlap at all, not whether the intersection meets a custom threshold. Meanwhile, the observer only fires when the ratio crosses a value listed in thresholds.
Follow that logic through a smooth scroll down:
- When
stagedrops from 16% visible to 14%, the observer crosses0.15and fires — withisIntersectingstilltrue, sostudy-scrolledstaysfalse. - When
stageleaves the viewport completely (0%),0is not in thethresholdlist, so no second callback fires. The ivory overlay stays stuck for the rest of the page.
Both the automated reviewer and my coding assistant arrived at that exact chain of reasoning independently. It sounded like independent confirmation. It was not: both systems were reasoning from the same specification prose without running a browser.
What actually happened in the browser
Testing the live site at https://www.frankxue.dev/ in Chromium (1280x860, light mode, #studyStage height 861px) produced the opposite result on both real scroll paths:
- Clicking the
#overviewanchor (Status & notes ↓): the page landed atscrollY = 777.5with83pxof#studyStagestill visible (~9.6%, below15%).study-scrolledflipped straight totrue. - Incremental mouse-wheel scrolling (11 steps of
120pxwith80mspauses):study-scrolledstayedfalsethrough step 6 (scrollY = 720,stage.bottom = 141px), flipped totrueon step 7 (scrollY = 840,stage.bottom = 21px, ~2.4%visible), and stayedtruedown toscrollY = 1320.
The gap between the argument and the screenshot is a documented web-platform discrepancy: W3C IntersectionObserver issue #432 (“isIntersecting definition doesn’t match browsers when thresholds are involved”). In Chromium’s Blink engine (and historically WebKit), isIntersecting is tied to whether the target clears the minimum configured threshold (thresholdIndex > 0) rather than purely geometric overlap. Dropping below 0.15 flips isIntersecting to false immediately.
One explicit limit on that test: I verified the old code in Chromium only. I did not run Firefox or Safari against the threshold: 0.15 version, so my live check settles what happened in Chromium — it does not prove every engine behaves identically on a non-zero threshold.
Why I still rewrote the observer
Even though the live page was not broken in Chromium, I opened PR #140 to replace the two threshold lines:
if ('IntersectionObserver' in window) {
new IntersectionObserver((entries) => {
document.body.classList.toggle('study-scrolled', !entries[0].isIntersecting);
}, { rootMargin: '-96px 0px 0px 0px', threshold: 0 }).observe(stage);
} else {
const onScroll = () => {
document.body.classList.toggle('study-scrolled', stage.getBoundingClientRect().bottom < 96);
};
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
}
Not to quiet a bot, but for three concrete engineering reasons:
threshold: 0removes the spec crack. At zero threshold, literal geometric intersection andthresholdIndex > 0mean the same thing across Blink, WebKit, Gecko, and static analysis.- A pixel offset behaves consistently across viewport heights.
0.15on a1440px-tall portrait display flips the header216pxbefore the study leaves the screen, putting a light bar over the dark scene early.-96pxtriggers at the same physical distance from the sticky header (~65–72px) on every monitor. -96pxclears the#overviewlanding edge. On this site,.herousesscroll-margin-top: 5rem(80pxat the default16pxroot font size). A-80pxroot margin would leavestage.bottomtouching the shrunk root’s top edge at80px, where W3C edge-adjacency still counts as intersecting. Adding16pxof clearance avoids that boundary, and matching the scroll fallback to< 96keeps both paths aligned.
Testing the PR #140 build locally in Chromium (1280x860, light mode) on both / and /zh/ confirmed all three transitions with zero console errors: #overview landed at stage.bottom = 82–83px (study-scrolled: true), incremental wheel scroll down flipped at stage.bottom = 80px, and scrolling back up restored study-scrolled: false once stage.bottom passed 96px (observed at 200px).
There is a small trade-off: -96px is a fixed pixel margin tuned to the header height at the default 16px root font size. If a visitor scales their browser’s base font size high enough that 5rem exceeds 96px, clicking #overview keeps the dark study overlay over the remaining strip of dark canvas until they scroll a few pixels further, rather than switching immediately on landing.
The habit worth keeping
AI code review is useful, and an AI coding assistant is fast at reading diffs. The failure mode to watch for is treating their agreement as independent verification. When both models reason from the same specification text without executing the code, their errors are correlated — and a confident second explanation makes a false positive look urgent.
Asking “show me it breaking” takes two minutes in a browser. It separates a live incident from a spec ambiguity, and lets you decide calmly whether the code still deserves a cleaner write-up.