2023-02-17 09:21:02 +00:00
|
|
|
import type { PageContext } from './types'
|
2023-11-14 15:10:00 +00:00
|
|
|
import type { PageContextBuiltInClientWithClientRouting } from 'vike/types'
|
|
|
|
|
|
|
|
import * as Sentry from '@sentry/browser'
|
2023-11-04 15:37:28 +00:00
|
|
|
import i18next from 'i18next'
|
2023-02-17 09:21:02 +00:00
|
|
|
import HttpApi from 'i18next-http-backend'
|
2023-11-14 15:10:00 +00:00
|
|
|
import ICU from 'i18next-icu'
|
|
|
|
import { hydrate } from 'solid-js/web'
|
|
|
|
|
|
|
|
import { App } from '../components/App'
|
|
|
|
import { initRouter } from '../stores/router'
|
2023-07-18 13:33:23 +00:00
|
|
|
import { SENTRY_DSN } from '../utils/config'
|
2023-07-18 15:42:34 +00:00
|
|
|
import { resolveHydrationPromise } from '../utils/hydrationPromise'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
let layoutReady = false
|
|
|
|
|
2023-07-18 13:33:23 +00:00
|
|
|
export const render = async (pageContext: PageContextBuiltInClientWithClientRouting & PageContext) => {
|
2023-07-31 20:19:08 +00:00
|
|
|
const { lng, pageProps, is404 } = pageContext
|
|
|
|
|
|
|
|
if (is404) {
|
|
|
|
initRouter('/404')
|
|
|
|
} else {
|
|
|
|
const { pathname, search } = window.location
|
|
|
|
const searchParams = Object.fromEntries(new URLSearchParams(search))
|
|
|
|
initRouter(pathname, searchParams)
|
|
|
|
}
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-07-18 13:33:23 +00:00
|
|
|
if (SENTRY_DSN) {
|
|
|
|
Sentry.init({
|
2023-11-14 15:10:00 +00:00
|
|
|
dsn: SENTRY_DSN,
|
2023-07-18 13:33:23 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-04 15:37:28 +00:00
|
|
|
// eslint-disable-next-line import/no-named-as-default-member
|
|
|
|
await i18next
|
|
|
|
.use(HttpApi)
|
|
|
|
.use(ICU)
|
|
|
|
.init({
|
|
|
|
// debug: true,
|
|
|
|
supportedLngs: ['ru', 'en'],
|
|
|
|
fallbackLng: lng,
|
|
|
|
lng,
|
2023-11-14 15:10:00 +00:00
|
|
|
load: 'languageOnly',
|
2023-11-04 15:37:28 +00:00
|
|
|
})
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-05-08 12:25:48 +00:00
|
|
|
const isIOSorMacOSorAndroid = /iphone|ipad|ipod|macintosh|android/i.test(navigator.userAgent)
|
|
|
|
|
|
|
|
if (!isIOSorMacOSorAndroid) {
|
|
|
|
const htmlEl = document.querySelector('html')
|
|
|
|
htmlEl.dataset.customScroll = 'on'
|
|
|
|
}
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
const content = document.querySelector('#root')
|
|
|
|
|
|
|
|
if (!layoutReady) {
|
2023-11-14 10:45:44 +00:00
|
|
|
hydrate(() => <App {...pageProps} />, content)
|
2023-02-17 09:21:02 +00:00
|
|
|
layoutReady = true
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 15:42:34 +00:00
|
|
|
|
|
|
|
export const onHydrationEnd = () => {
|
|
|
|
resolveHydrationPromise()
|
|
|
|
}
|