074c555294
post session info to service worker instead of asking from sw on each request
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
/* eslint-disable import/first */
|
|
import React from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { enableMapSet } from 'immer';
|
|
import '@fontsource/inter/variable.css';
|
|
import 'folds/dist/style.css';
|
|
import { configClass, varsClass } from 'folds';
|
|
|
|
enableMapSet();
|
|
|
|
import './index.css';
|
|
|
|
import { trimTrailingSlash } from './app/utils/common';
|
|
import App from './app/pages/App';
|
|
|
|
// import i18n (needs to be bundled ;))
|
|
import './app/i18n';
|
|
import { pushSessionToSW } from './sw-session';
|
|
import { getFallbackSession } from './app/state/sessions';
|
|
|
|
document.body.classList.add(configClass, varsClass);
|
|
|
|
// Register Service Worker
|
|
if ('serviceWorker' in navigator) {
|
|
const swUrl =
|
|
import.meta.env.MODE === 'production'
|
|
? `${trimTrailingSlash(import.meta.env.BASE_URL)}/sw.js`
|
|
: `/dev-sw.js?dev-sw`;
|
|
|
|
navigator.serviceWorker.register(swUrl).then(() => {
|
|
const session = getFallbackSession();
|
|
pushSessionToSW(session?.baseUrl, session?.accessToken);
|
|
});
|
|
}
|
|
|
|
const mountApp = () => {
|
|
const rootContainer = document.getElementById('root');
|
|
|
|
if (rootContainer === null) {
|
|
console.error('Root container element not found!');
|
|
return;
|
|
}
|
|
|
|
const root = createRoot(rootContainer);
|
|
root.render(<App />);
|
|
};
|
|
|
|
mountApp();
|