Skip to content

Commit 2489f15

Browse files
committed
Do not trigger section intersection callbacks from static previews
Prevent triggering the callback when link preview tooltips are displayed. REDMINE-20481
1 parent 05c9ec9 commit 2489f15

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

entry_types/scrolled/package/spec/frontend/SectionIntersectionObserver-spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
SectionIntersectionProbe
66
} from 'frontend/SectionIntersectionObserver';
77

8+
import {StaticPreview} from 'frontend/useScrollPositionLifecycle';
9+
810
import {
911
fakeIntersectionObserver,
1012
simulateScrollingIntoView,
@@ -256,4 +258,26 @@ describe('SectionIntersectionObserver', () => {
256258
expect(observeSpy).not.toHaveBeenCalled();
257259
expect(unobserveSpy).not.toHaveBeenCalled();
258260
});
261+
262+
it('is no-op inside StaticPreview', () => {
263+
const sections = [
264+
{id: 1}
265+
];
266+
const callback = jest.fn();
267+
268+
const {getByTestId} = render(
269+
<SectionIntersectionObserver sections={sections}
270+
onChange={callback}>
271+
<StaticPreview>
272+
<section data-testid="section1">
273+
<SectionIntersectionProbe section={sections[0]} />
274+
</section>
275+
</StaticPreview>
276+
</SectionIntersectionObserver>
277+
);
278+
279+
simulateScrollingIntoView(getByTestId('section1'));
280+
281+
expect(callback).not.toHaveBeenCalled();
282+
});
259283
});

entry_types/scrolled/package/src/frontend/SectionIntersectionObserver.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import React, {
1010
import classNames from 'classnames';
1111

1212
import styles from './SectionIntersectionObserver.module.css';
13+
import {useIsStaticPreview} from './useScrollPositionLifecycle';
1314

1415
const SectionIntersectionObserverContext = createContext([]);
1516

@@ -69,10 +70,16 @@ export function SectionIntersectionObserver({sections, probeClassName, onChange,
6970
}
7071

7172
export function SectionIntersectionProbe({section}) {
73+
const isStaticPreview = useIsStaticPreview();
74+
7275
const observers = useContext(SectionIntersectionObserverContext);
7376
const probeRefs = useRef([]);
7477

7578
useEffect(() => {
79+
if (isStaticPreview) {
80+
return;
81+
}
82+
7683
const elements = probeRefs.current.slice();
7784

7885
observers.forEach(({observer}, index) => {
@@ -88,7 +95,7 @@ export function SectionIntersectionProbe({section}) {
8895
}
8996
});
9097
};
91-
}, [observers]);
98+
}, [observers, isStaticPreview]);
9299

93100
return observers.map(({probeClassName}, index) =>
94101
<div ref={el => probeRefs.current[index] = el}

0 commit comments

Comments
 (0)