index.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from "react";
  2. import ReactDOM from "react-dom";
  3. import * as Sentry from "@sentry/browser";
  4. import * as SentryIntegrations from "@sentry/integrations";
  5. import { EVENT } from "./constants";
  6. import { TopErrorBoundary } from "./components/TopErrorBoundary";
  7. import { IsMobileProvider } from "./is-mobile";
  8. import App from "./components/App";
  9. import { register as registerServiceWorker } from "./serviceWorker";
  10. import "./css/styles.scss";
  11. // On Apple mobile devices add the proprietary app icon and splashscreen markup.
  12. // No one should have to do this manually, and eventually this annoyance will
  13. // go away once https://bugs.webkit.org/show_bug.cgi?id=183937 is fixed.
  14. if (
  15. /\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent) &&
  16. !matchMedia("(display-mode: standalone)").matches
  17. ) {
  18. import(/* webpackChunkName: "pwacompat" */ "pwacompat");
  19. }
  20. const SentryEnvHostnameMap: { [key: string]: string } = {
  21. "excalidraw.com": "production",
  22. "now.sh": "staging",
  23. };
  24. const onlineEnv = Object.keys(SentryEnvHostnameMap).find(
  25. (item) => window.location.hostname.indexOf(item) >= 0,
  26. );
  27. Sentry.init({
  28. // Disable Sentry locally to avoid noise
  29. dsn: onlineEnv
  30. ? "https://7bfc596a5bf945eda6b660d3015a5460@sentry.io/5179260"
  31. : undefined,
  32. environment: onlineEnv ? SentryEnvHostnameMap[onlineEnv] : undefined,
  33. release: process.env.REACT_APP_GIT_SHA,
  34. ignoreErrors: [
  35. "undefined is not an object (evaluating 'window.__pad.performLoop')", // Only happens on Safari, but spams our servers. Doesn't break anything
  36. ],
  37. integrations: [
  38. new SentryIntegrations.CaptureConsole({
  39. levels: ["error"],
  40. }),
  41. ],
  42. });
  43. // Block pinch-zooming on iOS outside of the content area
  44. document.addEventListener(
  45. "touchmove",
  46. (event) => {
  47. // @ts-ignore
  48. if (event.scale !== 1) {
  49. event.preventDefault();
  50. }
  51. },
  52. { passive: false },
  53. );
  54. const rootElement = document.getElementById("root");
  55. ReactDOM.render(
  56. <TopErrorBoundary>
  57. <IsMobileProvider>
  58. <App />
  59. </IsMobileProvider>
  60. </TopErrorBoundary>,
  61. rootElement,
  62. );
  63. registerServiceWorker({
  64. onUpdate: (registration) => {
  65. const waitingServiceWorker = registration.waiting;
  66. if (waitingServiceWorker) {
  67. waitingServiceWorker.addEventListener(
  68. EVENT.STATE_CHANGE,
  69. (event: Event) => {
  70. const target = event.target as ServiceWorker;
  71. const state = target.state as ServiceWorkerState;
  72. if (state === "activated") {
  73. window.location.reload();
  74. }
  75. },
  76. );
  77. waitingServiceWorker.postMessage({ type: "SKIP_WAITING" });
  78. }
  79. },
  80. });