webapp/src/renderer/_default.page.client.tsx

63 lines
2.0 KiB
TypeScript
Raw Normal View History

import type { PageContextBuiltInClientWithClientRouting } from 'vike/types'
2024-02-04 11:25:21 +00:00
import type { PageContext } from './types'
2024-05-04 17:17:47 +00:00
import { init as SentryInit, replayIntegration } 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'
import ICU from 'i18next-icu'
import { hydrate } from 'solid-js/web'
import { App } from '../components/App'
import { initRouter } from '../stores/router'
2024-05-21 13:51:13 +00:00
import { errorsReportingDsn } from '../utils/config'
import { resolveHydrationPromise } from '../utils/hydrationPromise'
2023-02-17 09:21:02 +00:00
let layoutReady = false
export const render = async (pageContext: PageContextBuiltInClientWithClientRouting & PageContext) => {
const { lng, pageProps, is404 } = pageContext
2023-11-18 15:20:15 +00:00
const { pathname, search } = window.location
const searchParams = Object.fromEntries(new URLSearchParams(search))
initRouter(pathname, searchParams)
2024-04-10 13:37:09 +00:00
2024-05-04 17:17:47 +00:00
SentryInit({
2024-05-21 13:51:13 +00:00
dsn: errorsReportingDsn,
2024-04-10 14:02:58 +00:00
tracesSampleRate: 0.01,
2024-05-04 17:17:47 +00:00
integrations: [replayIntegration()],
2024-04-10 14:02:58 +00:00
// Session Replay
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
})
2024-04-10 13:37:09 +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,
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-18 15:20:15 +00:00
hydrate(() => <App {...pageProps} is404={is404} />, content)
2023-02-17 09:21:02 +00:00
layoutReady = true
}
}
export const onHydrationEnd = () => {
resolveHydrationPromise()
}