2023-06-12 21:15:23 +10:00
|
|
|
/* eslint-disable import/first */
|
2026-05-21 19:44:51 -04:00
|
|
|
import * as Sentry from '@sentry/react';
|
2021-07-28 18:45:52 +05:30
|
|
|
import React from 'react';
|
2024-01-21 23:50:56 +11:00
|
|
|
import { createRoot } from 'react-dom/client';
|
2023-06-12 21:15:23 +10:00
|
|
|
import { enableMapSet } from 'immer';
|
2026-05-21 23:30:50 -04:00
|
|
|
import '@fontsource-variable/inter/index.css';
|
2023-06-12 21:15:23 +10:00
|
|
|
import 'folds/dist/style.css';
|
|
|
|
|
import { configClass, varsClass } from 'folds';
|
|
|
|
|
|
2026-05-21 19:56:38 -04:00
|
|
|
const sentryDsn = import.meta.env.VITE_SENTRY_DSN;
|
|
|
|
|
if (sentryDsn) {
|
2026-05-21 19:44:51 -04:00
|
|
|
Sentry.init({
|
2026-05-21 19:56:38 -04:00
|
|
|
dsn: sentryDsn,
|
2026-05-21 19:44:51 -04:00
|
|
|
environment: import.meta.env.MODE,
|
|
|
|
|
release: import.meta.env.VITE_APP_VERSION,
|
2026-05-21 20:00:21 -04:00
|
|
|
// browserTracingIntegration omitted — it injects sentry-trace/baggage headers
|
|
|
|
|
// into outgoing fetch calls, which breaks Synapse CORS on matrix.lotusguild.org
|
|
|
|
|
// No propagation targets — we don't control the Matrix server's CORS allow-list
|
|
|
|
|
tracePropagationTargets: [],
|
|
|
|
|
tracesSampleRate: 0,
|
2026-05-21 19:56:38 -04:00
|
|
|
// Don't send PII (IPs, usernames) — this is a private chat app
|
2026-05-21 19:44:51 -04:00
|
|
|
sendDefaultPii: false,
|
2026-05-21 19:56:38 -04:00
|
|
|
// Forward Sentry logs to the dashboard
|
|
|
|
|
enableLogs: true,
|
2026-05-23 00:28:37 -04:00
|
|
|
// Suppress benign PostmessageTransport / matrixRTC heartbeat timeouts (upstream library noise)
|
|
|
|
|
ignoreErrors: ['Request timed out'],
|
2026-05-21 19:44:51 -04:00
|
|
|
beforeSend(event) {
|
2026-05-21 19:56:38 -04:00
|
|
|
// Drop any event that may have leaked an access token into breadcrumbs/data
|
|
|
|
|
if (JSON.stringify(event).includes('access_token')) return null;
|
2026-05-21 19:44:51 -04:00
|
|
|
return event;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
enableMapSet();
|
|
|
|
|
|
2025-08-29 15:04:52 +05:30
|
|
|
import './index.css';
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2024-09-07 21:45:55 +08:00
|
|
|
import { trimTrailingSlash } from './app/utils/common';
|
2021-07-28 18:45:52 +05:30
|
|
|
import App from './app/pages/App';
|
|
|
|
|
|
2024-08-14 15:29:34 +02:00
|
|
|
// import i18n (needs to be bundled ;))
|
|
|
|
|
import './app/i18n';
|
2026-02-14 11:41:36 +05:30
|
|
|
import { pushSessionToSW } from './sw-session';
|
|
|
|
|
import { getFallbackSession } from './app/state/sessions';
|
2024-08-14 15:29:34 +02:00
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
document.body.classList.add(configClass, varsClass);
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2024-09-07 21:45:55 +08:00
|
|
|
// Register Service Worker
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
2024-09-09 18:45:20 +10:00
|
|
|
const swUrl =
|
|
|
|
|
import.meta.env.MODE === 'production'
|
|
|
|
|
? `${trimTrailingSlash(import.meta.env.BASE_URL)}/sw.js`
|
|
|
|
|
: `/dev-sw.js?dev-sw`;
|
|
|
|
|
|
2026-02-16 14:21:09 +05:30
|
|
|
const sendSessionToSW = () => {
|
2026-02-14 11:41:36 +05:30
|
|
|
const session = getFallbackSession();
|
|
|
|
|
pushSessionToSW(session?.baseUrl, session?.accessToken);
|
2026-02-16 14:21:09 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.register(swUrl).then(sendSessionToSW);
|
|
|
|
|
navigator.serviceWorker.ready.then(sendSessionToSW);
|
|
|
|
|
|
2026-02-21 12:21:27 +05:30
|
|
|
navigator.serviceWorker.addEventListener('message', (ev) => {
|
|
|
|
|
const { type } = ev.data ?? {};
|
|
|
|
|
|
|
|
|
|
if (type === 'requestSession') {
|
2026-02-16 14:21:09 +05:30
|
|
|
sendSessionToSW();
|
|
|
|
|
}
|
2024-09-09 18:45:20 +10:00
|
|
|
});
|
2024-09-07 21:45:55 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-22 02:31:54 -04:00
|
|
|
// Reload once if a lazy-loaded chunk is missing (stale deployment)
|
2026-05-22 10:46:55 -04:00
|
|
|
window.addEventListener('vite:preloadError', () => {
|
|
|
|
|
if (!sessionStorage.getItem('chunk-reload-attempted')) {
|
|
|
|
|
sessionStorage.setItem('chunk-reload-attempted', '1');
|
2026-05-22 02:31:54 -04:00
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// Clear the reload flag after a successful load so future deploys can still trigger a reload
|
2026-05-22 10:46:55 -04:00
|
|
|
window.addEventListener('load', () => sessionStorage.removeItem('chunk-reload-attempted'));
|
2026-05-22 02:31:54 -04:00
|
|
|
|
2026-05-22 16:33:24 -04:00
|
|
|
// Synapse does not yet ship MSC3786/MSC3914 as server-default push rules.
|
|
|
|
|
// matrix-js-sdk patches them client-side on every login and logs a warn for each.
|
|
|
|
|
// Suppress the noise until Synapse implements these MSCs upstream.
|
|
|
|
|
{
|
|
|
|
|
const _warn = console.warn.bind(console);
|
|
|
|
|
console.warn = (...args: unknown[]) => {
|
|
|
|
|
if (typeof args[0] === 'string' && args[0].startsWith('Adding default global ')) return;
|
|
|
|
|
_warn(...args);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-21 23:50:56 +11:00
|
|
|
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();
|