2017-05-12 00:23:56 +00:00
|
|
|
// @flow
|
2020-09-13 06:27:23 +00:00
|
|
|
import "focus-visible";
|
2021-07-12 18:57:17 +00:00
|
|
|
import { LazyMotion } from "framer-motion";
|
2021-10-24 19:30:27 +00:00
|
|
|
import { KBarProvider } from "kbar";
|
2020-08-09 05:53:59 +00:00
|
|
|
import { Provider } from "mobx-react";
|
2020-06-20 20:59:15 +00:00
|
|
|
import * as React from "react";
|
|
|
|
import { render } from "react-dom";
|
2021-01-23 04:42:45 +00:00
|
|
|
import { Router } from "react-router-dom";
|
2020-11-30 04:04:58 +00:00
|
|
|
import { initI18n } from "shared/i18n";
|
2020-08-09 05:53:59 +00:00
|
|
|
import stores from "stores";
|
2021-03-30 05:02:38 +00:00
|
|
|
import Analytics from "components/Analytics";
|
2021-10-24 19:30:27 +00:00
|
|
|
import { CommandBarOptions } from "components/CommandBar";
|
|
|
|
import Dialogs from "components/Dialogs";
|
2020-06-20 20:59:15 +00:00
|
|
|
import ErrorBoundary from "components/ErrorBoundary";
|
2021-02-15 23:19:51 +00:00
|
|
|
import PageTheme from "components/PageTheme";
|
2020-06-20 20:59:15 +00:00
|
|
|
import ScrollToTop from "components/ScrollToTop";
|
|
|
|
import Theme from "components/Theme";
|
2020-08-09 05:53:59 +00:00
|
|
|
import Toasts from "components/Toasts";
|
2020-06-20 20:59:15 +00:00
|
|
|
import Routes from "./routes";
|
2021-10-24 19:30:27 +00:00
|
|
|
import history from "./utils/history";
|
2021-09-15 01:04:35 +00:00
|
|
|
import { initSentry } from "./utils/sentry";
|
2020-07-18 18:02:40 +00:00
|
|
|
import env from "env";
|
2017-09-04 21:48:56 +00:00
|
|
|
|
2020-11-30 04:04:58 +00:00
|
|
|
initI18n();
|
|
|
|
|
2021-02-15 23:19:51 +00:00
|
|
|
const element = window.document.getElementById("root");
|
2021-01-23 04:42:45 +00:00
|
|
|
|
|
|
|
if (env.SENTRY_DSN) {
|
|
|
|
initSentry(history);
|
|
|
|
}
|
2018-05-05 23:16:08 +00:00
|
|
|
|
2021-02-15 23:19:51 +00:00
|
|
|
if ("serviceWorker" in window.navigator) {
|
|
|
|
window.addEventListener("load", () => {
|
2021-04-23 19:31:27 +00:00
|
|
|
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
|
|
|
|
// In some rare (<0.1% of cases) this call can return `undefined`
|
|
|
|
const maybePromise = window.navigator.serviceWorker.register(
|
|
|
|
"/static/service-worker.js",
|
|
|
|
{
|
2021-02-15 23:19:51 +00:00
|
|
|
scope: "/",
|
2021-04-23 19:31:27 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-04-24 19:50:30 +00:00
|
|
|
if (maybePromise && maybePromise.then) {
|
2021-04-23 19:31:27 +00:00
|
|
|
maybePromise
|
|
|
|
.then((registration) => {
|
|
|
|
console.log("SW registered: ", registration);
|
|
|
|
})
|
|
|
|
.catch((registrationError) => {
|
|
|
|
console.log("SW registration failed: ", registrationError);
|
|
|
|
});
|
|
|
|
}
|
2021-02-15 23:19:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-12 18:57:17 +00:00
|
|
|
// Make sure to return the specific export containing the feature bundle.
|
|
|
|
const loadFeatures = () =>
|
|
|
|
import("./utils/motion.js").then((res) => res.default);
|
|
|
|
|
2018-05-05 23:16:08 +00:00
|
|
|
if (element) {
|
2021-04-11 22:09:00 +00:00
|
|
|
const App = () => (
|
2021-06-05 21:59:14 +00:00
|
|
|
<React.StrictMode>
|
|
|
|
<Provider {...stores}>
|
|
|
|
<Analytics>
|
|
|
|
<Theme>
|
|
|
|
<ErrorBoundary>
|
2021-10-24 19:30:27 +00:00
|
|
|
<KBarProvider actions={[]} options={CommandBarOptions}>
|
|
|
|
<LazyMotion features={loadFeatures}>
|
|
|
|
<Router history={history}>
|
|
|
|
<>
|
|
|
|
<PageTheme />
|
|
|
|
<ScrollToTop>
|
|
|
|
<Routes />
|
|
|
|
</ScrollToTop>
|
|
|
|
<Toasts />
|
|
|
|
<Dialogs />
|
|
|
|
</>
|
|
|
|
</Router>
|
|
|
|
</LazyMotion>
|
|
|
|
</KBarProvider>
|
2021-06-05 21:59:14 +00:00
|
|
|
</ErrorBoundary>
|
|
|
|
</Theme>
|
|
|
|
</Analytics>
|
|
|
|
</Provider>
|
|
|
|
</React.StrictMode>
|
2018-05-05 23:16:08 +00:00
|
|
|
);
|
2021-04-11 22:09:00 +00:00
|
|
|
|
|
|
|
render(<App />, element);
|
2018-05-05 23:16:08 +00:00
|
|
|
}
|
2018-02-11 07:23:50 +00:00
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
window.addEventListener("load", async () => {
|
2018-02-11 07:23:50 +00:00
|
|
|
// installation does not use Google Analytics, or tracking is blocked on client
|
|
|
|
// no point loading the rest of the analytics bundles
|
2020-07-18 18:02:40 +00:00
|
|
|
if (!env.GOOGLE_ANALYTICS_ID || !window.ga) return;
|
2018-02-11 07:23:50 +00:00
|
|
|
|
2018-02-11 07:54:54 +00:00
|
|
|
// https://github.com/googleanalytics/autotrack/issues/137#issuecomment-305890099
|
2021-06-13 22:23:53 +00:00
|
|
|
await import(/* webpackChunkName: "autotrack" */ "autotrack/autotrack.js");
|
2018-02-11 07:23:50 +00:00
|
|
|
|
2020-06-20 20:59:15 +00:00
|
|
|
window.ga("require", "outboundLinkTracker");
|
|
|
|
window.ga("require", "urlChangeTracker");
|
|
|
|
window.ga("require", "eventTracker", {
|
|
|
|
attributePrefix: "data-",
|
2019-06-25 05:14:59 +00:00
|
|
|
});
|
2018-02-11 07:23:50 +00:00
|
|
|
});
|