Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Add fallback if InteractionObserver is unavailable

Uku Taht97ce263c841b
diff --git a/assets/js/dashboard/components/lazy-loader.js b/assets/js/dashboard/components/lazy-loader.js
index dd15c36eb6..c06de0de95 100644
--- a/assets/js/dashboard/components/lazy-loader.js
+++ b/assets/js/dashboard/components/lazy-loader.js
@@ -2,6 +2,14 @@ import React from 'react';
export default class extends React.Component {
componentDidMount() {
+ if ('IntersectionObserver' in window) {
+ this.attachObserver()
+ } else {
+ this.props.onVisible && this.props.onVisible()
+ }
+ }
+
+ attachObserver() {
this.observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
this.props.onVisible && this.props.onVisible()
diff --git a/assets/js/dashboard/historical.js b/assets/js/dashboard/historical.js
index b910af02a7..12d4a2f43d 100644
--- a/assets/js/dashboard/historical.js
+++ b/assets/js/dashboard/historical.js
@@ -25,12 +25,10 @@ function Historical(props) {
return null
}
- const navClass = props.site.embedded ? 'relative' : 'sticky'
-
return (
<div className="mb-12">
<div id="stats-container-top"></div>
- <div className={`${navClass} top-0 sm:py-3 py-2 z-10 ${props.stuck && !props.site.embedded ? 'fullwidth-shadow bg-gray-50 dark:bg-gray-850' : ''}`}>
+ <div className={`relative top-0 sm:py-3 py-2 z-10 ${props.stuck && !props.site.embedded ? 'sticky fullwidth-shadow bg-gray-50 dark:bg-gray-850' : ''}`}>
<div className="items-center w-full flex">
<div className="flex items-center w-full">
<SiteSwitcher site={props.site} loggedIn={props.loggedIn} currentUserRole={props.currentUserRole} />
diff --git a/assets/js/dashboard/pinned-header-hoc.js b/assets/js/dashboard/pinned-header-hoc.js
index d770213b7e..ded8331e06 100644
--- a/assets/js/dashboard/pinned-header-hoc.js
+++ b/assets/js/dashboard/pinned-header-hoc.js
@@ -10,6 +10,12 @@ export const withPinnedHeader = (WrappedComponent, selector) => {
}
componentDidMount() {
+ if ('IntersectionObserver' in window) {
+ this.attachObserver()
+ }
+ }
+
+ attachObserver() {
this.observer = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio === 0)
this.setState({ stuck: true });