Skip to content

Commit 3375693

Browse files
Copilotalexr00
andcommitted
Fix IntersectionObserver to prevent stuck state on page load
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 53ff457 commit 3375693

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

webviews/editorWebview/overview.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,23 @@ export const Overview = (pr: PullRequest) => {
4242
return;
4343
}
4444

45-
// Use IntersectionObserver to detect when the sentinel leaves the viewport
46-
// This indicates the title is stuck
45+
// Use IntersectionObserver to detect when the title becomes sticky
46+
// The sentinel is positioned right above the title
47+
// When sentinel scrolls out of view (top of viewport), title becomes stuck
4748
const observer = new IntersectionObserver(
4849
([entry]) => {
49-
// When sentinel is not intersecting, title is stuck
50+
// When sentinel is visible, title hasn't become stuck yet
51+
// When sentinel is not visible (scrolled past top), title is stuck
5052
if (entry.isIntersecting) {
5153
title.classList.remove('stuck');
5254
} else {
5355
title.classList.add('stuck');
5456
}
5557
},
5658
{
57-
threshold: [1],
58-
rootMargin: '0px'
59+
// Use rootMargin to trigger slightly before reaching the top
60+
rootMargin: '-1px 0px 0px 0px',
61+
threshold: [1]
5962
}
6063
);
6164

@@ -67,8 +70,8 @@ export const Overview = (pr: PullRequest) => {
6770
}, []);
6871

6972
return <>
70-
{/* Sentinel element that sits just above the sticky title */}
71-
<div ref={sentinelRef} style={{ height: '1px', marginTop: '-1px' }} />
73+
{/* Sentinel element positioned just before the sticky title - must have height to be observable */}
74+
<div ref={sentinelRef} style={{ height: '1px' }} />
7275
<div id="title" className="title" ref={titleRef}>
7376
<div className="details">
7477
<Header {...pr} />

0 commit comments

Comments
 (0)