aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/index.js
blob: 6c557ae74866a0e70cfc534c3ce1e4984e0864b6 (plain) (blame)
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
import { StrictMode, lazy } from 'react';
import { hydrateRoot } from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { CookiesProvider } from 'react-cookie';

import { VisitorProvider } from './ui/VisitorContext';

const Juick = lazy(() => import('./App'));

function fromBinary(encoded) {
    const binary = window.atob(encoded);
    const bytes = new Uint8Array(binary.length);
    for (let i = 0; i < bytes.length; i++) {
        bytes[i] = binary.charCodeAt(i);
    }
    return String.fromCharCode(...new Uint16Array(bytes.buffer));
}

const props = window.__PROPS__ ? JSON.parse(fromBinary(window.__PROPS__)) : {};

const JuickApp = () => (
    <StrictMode>
        <VisitorProvider>
            <CookiesProvider>
                <BrowserRouter>
                    <Juick {...props} />
                </BrowserRouter>
            </CookiesProvider>
        </VisitorProvider>
    </StrictMode>
);

hydrateRoot(document.getElementById('app'), <JuickApp />);