-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry.client.tsx
More file actions
46 lines (43 loc) · 1.28 KB
/
entry.client.tsx
File metadata and controls
46 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import i18next from 'i18next'
import I18nextBrowserLanguageDetector from 'i18next-browser-languagedetector'
import I18NextHttpBackend from 'i18next-http-backend'
import { startTransition, StrictMode } from 'react'
import { hydrateRoot } from 'react-dom/client'
import { I18nextProvider, initReactI18next } from 'react-i18next'
import { HydratedRouter } from 'react-router/dom'
import { getInitialNamespaces } from 'remix-i18next/client'
import { i18nextOptions } from './i18next-config'
const hydrate = async () => {
await i18next
.use(initReactI18next)
.use(I18NextHttpBackend)
// The language detector only uses htmlTag which is set
// in root.tsx, so it won't cause hydration mismatches.
.use(I18nextBrowserLanguageDetector)
.init({
...i18nextOptions,
ns: getInitialNamespaces(),
backend: { loadPath: '/locales/{{lng}}/{{ns}}.json' },
detection: {
order: ['htmlTag'],
caches: [],
},
})
startTransition(() => {
hydrateRoot(
document,
<I18nextProvider i18n={i18next}>
<StrictMode>
<HydratedRouter />
</StrictMode>
</I18nextProvider>,
)
})
}
if (window.requestIdleCallback) {
window.requestIdleCallback(hydrate)
} else {
// Safari doesn't support requestIdleCallback
// https://caniuse.com/requestidlecallback
window.setTimeout(hydrate, 1)
}