Skip to content

Commit c5b3f97

Browse files
committed
unobserve element once viewed. Update priority to feature
1 parent 1fe74ce commit c5b3f97

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

dotcom-rendering/src/components/FrontSectionTracker.importable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const getCollectionElements = (): HTMLElement[] => {
1111
const reportInsertEvent = (elements: HTMLElement[]) => {
1212
for (const [index, element] of elements.entries()) {
1313
const sectionName = element.id;
14-
if (sectionName === '') return;
14+
if (sectionName === '') continue;
1515

1616
const distanceFromTop = (
1717
element.getBoundingClientRect().top + window.pageYOffset
@@ -65,6 +65,8 @@ const setCollectionAsViewed = (id: string) => {
6565
*/
6666
export const FrontSectionTracker = () => {
6767
useEffect(() => {
68+
if (!('IntersectionObserver' in window)) return;
69+
6870
const collectionElements: HTMLElement[] = getCollectionElements();
6971

7072
void reportInsertEvent(collectionElements);
@@ -76,6 +78,7 @@ export const FrontSectionTracker = () => {
7678
if (!viewedCollections.has(sectionName)) {
7779
setCollectionAsViewed(sectionName);
7880
reportViewEvent(sectionName);
81+
observer.unobserve(entry.target);
7982
}
8083
}
8184
}

dotcom-rendering/src/layouts/FrontLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ export const FrontLayout = ({ front, NAV }: Props) => {
748748
</Island>
749749
</BannerWrapper>
750750

751-
<Island priority="enhancement" defer={{ until: 'idle' }}>
751+
<Island priority="feature" defer={{ until: 'idle' }}>
752752
<FrontSectionTracker />
753753
</Island>
754754
</>

0 commit comments

Comments
 (0)