diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx
index 5241c6d8..61eb5d09 100644
--- a/src/components/Article/FullArticle.tsx
+++ b/src/components/Article/FullArticle.tsx
@@ -57,12 +57,12 @@ export type ArticlePageSearchParams = {
const scrollTo = (el: HTMLElement) => {
const { top } = el.getBoundingClientRect()
- if (window)
- window.scrollTo({
- top: top + window.scrollY - DEFAULT_HEADER_OFFSET,
- left: 0,
- behavior: 'smooth'
- })
+
+ window?.scrollTo({
+ top: top + window.scrollY - DEFAULT_HEADER_OFFSET,
+ left: 0,
+ behavior: 'smooth'
+ })
}
const imgSrcRegExp = /
]+src\s*=\s*["']([^"']+)["']/gi
@@ -270,7 +270,8 @@ export const FullArticle = (props: Props) => {
// Check iframes size
let articleContainer: HTMLElement | undefined
const updateIframeSizes = () => {
- if (!(articleContainer && props.article.body && window)) return
+ if (!window) return
+ if (!(articleContainer && props.article.body)) return
const iframes = articleContainer?.querySelectorAll('iframe')
if (!iframes) return
const containerWidth = articleContainer?.offsetWidth
diff --git a/src/components/Nav/Header/Header.tsx b/src/components/Nav/Header/Header.tsx
index 860cf41a..4c72f414 100644
--- a/src/components/Nav/Header/Header.tsx
+++ b/src/components/Nav/Header/Header.tsx
@@ -71,7 +71,7 @@ export const Header = (props: Props) => {
const mainContent = document.querySelector('.main-content')
if (fixed() || modal() !== null) {
- windowScrollTop = window.scrollY
+ windowScrollTop = window?.scrollY || 0
if (mainContent) mainContent.style.marginTop = `-${windowScrollTop}px`
}
@@ -79,7 +79,7 @@ export const Header = (props: Props) => {
document.body.classList.toggle(styles.fixed, fixed() && !modal())
if (!(fixed() || modal())) {
- window.scrollTo(0, windowScrollTop)
+ window?.scrollTo(0, windowScrollTop)
if (mainContent) mainContent.style.marginTop = ''
}
})
diff --git a/src/components/NotificationsPanel/NotificationsPanel.tsx b/src/components/NotificationsPanel/NotificationsPanel.tsx
index a40448e7..7409dd2d 100644
--- a/src/components/NotificationsPanel/NotificationsPanel.tsx
+++ b/src/components/NotificationsPanel/NotificationsPanel.tsx
@@ -75,7 +75,7 @@ export const NotificationsPanel = (props: Props) => {
const mainContent = document.querySelector('.main-content')
if (props.isOpen && mainContent && window) {
- windowScrollTop = window.scrollY
+ windowScrollTop = window?.scrollY || 0
mainContent.style.marginTop = `-${windowScrollTop}px`
}
@@ -83,7 +83,7 @@ export const NotificationsPanel = (props: Props) => {
if (!props.isOpen && mainContent && window) {
mainContent.style.marginTop = ''
- window.scrollTo(0, windowScrollTop)
+ window?.scrollTo(0, windowScrollTop)
}
})
diff --git a/src/components/TableOfContents/TableOfContents.tsx b/src/components/TableOfContents/TableOfContents.tsx
index 971163d6..0373e715 100644
--- a/src/components/TableOfContents/TableOfContents.tsx
+++ b/src/components/TableOfContents/TableOfContents.tsx
@@ -20,14 +20,13 @@ const isInViewport = (el: Element): boolean => {
return rect.top <= DEFAULT_HEADER_OFFSET + 24 // default offset + 1.5em (default header margin-top)
}
const scrollToHeader = (element: HTMLElement) => {
- if (window)
- window.scrollTo({
- behavior: 'smooth',
- top:
- element.getBoundingClientRect().top -
- document.body.getBoundingClientRect().top -
- DEFAULT_HEADER_OFFSET
- })
+ window?.scrollTo({
+ behavior: 'smooth',
+ top:
+ element.getBoundingClientRect().top -
+ document?.body.getBoundingClientRect().top -
+ DEFAULT_HEADER_OFFSET
+ })
}
export const TableOfContents = (props: Props) => {
diff --git a/src/components/Views/EditView/EditSettingsView.tsx b/src/components/Views/EditView/EditSettingsView.tsx
index 9337c33a..7a557bed 100644
--- a/src/components/Views/EditView/EditSettingsView.tsx
+++ b/src/components/Views/EditView/EditSettingsView.tsx
@@ -33,7 +33,7 @@ const AUTO_SAVE_DELAY = 3000
const handleScrollTopButtonClick = (ev: MouseEvent | TouchEvent) => {
ev.preventDefault()
- window.scrollTo({
+ window?.scrollTo({
top: 0,
behavior: 'smooth'
})
diff --git a/src/components/Views/EditView/EditView.tsx b/src/components/Views/EditView/EditView.tsx
index 8a70be74..07bdc909 100644
--- a/src/components/Views/EditView/EditView.tsx
+++ b/src/components/Views/EditView/EditView.tsx
@@ -55,7 +55,7 @@ const AUTO_SAVE_DELAY = 3000
const handleScrollTopButtonClick = (ev: MouseEvent | TouchEvent) => {
ev.preventDefault()
- window.scrollTo({
+ window?.scrollTo({
top: 0,
behavior: 'smooth'
})
diff --git a/src/components/Views/Profile/ProfileSecurity.tsx b/src/components/Views/Profile/ProfileSecurity.tsx
index 934a3dc1..e07407c4 100644
--- a/src/components/Views/Profile/ProfileSecurity.tsx
+++ b/src/components/Views/Profile/ProfileSecurity.tsx
@@ -87,8 +87,8 @@ export const ProfileSecurityView = (_props: any) => {
handleInputChange('newPasswordConfirm', value)
if (newPasswordRepeatRef && value !== formData()['newPassword']) {
const rect = newPasswordRepeatRef.getBoundingClientRect()
- const topPosition = window.scrollY + rect.top - DEFAULT_HEADER_OFFSET * 2
- window.scrollTo({
+ const topPosition = (window?.scrollY || 0) + rect.top - DEFAULT_HEADER_OFFSET * 2
+ window?.scrollTo({
top: topPosition,
left: 0,
behavior: 'smooth'
@@ -117,8 +117,8 @@ export const ProfileSecurityView = (_props: any) => {
setOldPasswordError(t('Incorrect old password'))
showSnackbar({ type: 'error', body: t('Incorrect old password') })
const rect = oldPasswordRef.getBoundingClientRect()
- const topPosition = window.scrollY + rect.top - DEFAULT_HEADER_OFFSET * 2
- window.scrollTo({
+ const topPosition = (window?.scrollY || 0) + rect.top - DEFAULT_HEADER_OFFSET * 2
+ window?.scrollTo({
top: topPosition,
left: 0,
behavior: 'smooth'
diff --git a/src/context/topics.tsx b/src/context/topics.tsx
index 93f45a87..4f60da6e 100644
--- a/src/context/topics.tsx
+++ b/src/context/topics.tsx
@@ -44,7 +44,7 @@ const STORE_NAME = 'topics'
const CACHE_LIFETIME = 24 * 60 * 60 * 1000 // один день в миллисекундах
const setupIndexedDB = async () => {
- if (!('indexedDB' in window)) {
+ if (window && !('indexedDB' in window)) {
console.error("This browser doesn't support IndexedDB")
return
}
diff --git a/src/intl/Translatable.tsx b/src/intl/Translatable.tsx
index f7e74468..77d50ae2 100644
--- a/src/intl/Translatable.tsx
+++ b/src/intl/Translatable.tsx
@@ -35,15 +35,15 @@ export default function TranslationWrapper(props: TranslationWrapperProps): JSX.
const [isTranslating, setIsTranslating] = createSignal(false)
onMount(async () => {
- if ('translation' in window) {
- const translation = (window as Window).translation
+ if (window && 'translation' in window) {
+ const translation = (window as Window)?.translation
const canTranslate = await translation?.canTranslate({
sourceLanguage: props.sourceLanguage || 'ru',
targetLanguage: props.targetLanguage
})
- if (canTranslate !== 'no') {
+ if (translation && canTranslate !== 'no') {
setIsTranslating(true)
try {
diff --git a/src/routes/[slug].tsx b/src/routes/[slug].tsx
index e7ff6c59..5bc4a774 100644
--- a/src/routes/[slug].tsx
+++ b/src/routes/[slug].tsx
@@ -48,9 +48,9 @@ export default (props: RouteSectionProps<{ article: Shout }>) => {
(a?: Shout) => {
if (!a) return
console.debug('[routes.slug] article found')
- window.gtag?.('event', 'page_view', {
+ window?.gtag?.('event', 'page_view', {
page_title: a.title,
- page_location: window.location.href,
+ page_location: window?.location.href || '',
page_path: loc.pathname
})
},
diff --git a/src/routes/author/[slug]/[tab].tsx b/src/routes/author/[slug]/[tab].tsx
index d05241f0..29e2c1ad 100644
--- a/src/routes/author/[slug]/[tab].tsx
+++ b/src/routes/author/[slug]/[tab].tsx
@@ -40,10 +40,10 @@ export default (props: RouteSectionProps<{ articles: Shout[] }>) => {
createReaction(() => {
if (author()) {
console.debug('[routes.slug] article signal changed once')
- window.gtag?.('event', 'page_view', {
+ window?.gtag?.('event', 'page_view', {
page_title: author()?.name || '',
- page_location: window.location.href,
- page_path: window.location.pathname
+ page_location: window?.location.href || '',
+ page_path: window?.location.pathname || ''
})
}
})
diff --git a/src/routes/edit/new.tsx b/src/routes/edit/new.tsx
index fa19260e..e88951ce 100644
--- a/src/routes/edit/new.tsx
+++ b/src/routes/edit/new.tsx
@@ -78,7 +78,7 @@ export default () => {
-