This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
entry.tsx
78 lines (67 loc) · 2.07 KB
/
entry.tsx
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import ReactDOM from 'react-dom';
import {logError} from 'mattermost-redux/actions/errors';
// Import our styles
import './sass/styles.scss';
import 'katex/dist/katex.min.css';
import '@mattermost/compass-icons/css/compass-icons.css';
import '@mattermost/components/dist/index.esm.css';
import {setCSRFFromCookie} from 'utils/utils';
import {AnnouncementBarTypes} from 'utils/constants';
import store from 'stores/redux_store.jsx';
import App from 'components/app';
declare global {
interface Window {
publicPath?: string;
}
}
// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup(callwhendone: () => void) {
window.onerror = (msg, url, line, column, error) => {
if (msg === 'ResizeObserver loop limit exceeded') {
return;
}
store.dispatch(
logError(
{
type: AnnouncementBarTypes.DEVELOPER,
message: 'A JavaScript error in the webapp client has occurred. (msg: ' + msg + ', row: ' + line + ', col: ' + column + ').',
stack: error?.stack,
url,
},
true,
true,
),
);
};
setCSRFFromCookie();
callwhendone();
}
function renderRootComponent() {
ReactDOM.render((
<App/>
),
document.getElementById('root'));
}
/**
* Adds a function to be invoked onload appended to any existing onload
* event handlers.
*/
function appendOnLoadEvent(fn: (evt: Event) => void) {
if (window.onload) {
const curronload = window.onload;
window.onload = (evt) => {
(curronload as any)(evt);
fn(evt);
};
} else {
window.onload = fn;
}
}
appendOnLoadEvent(() => {
// Do the pre-render setup and call renderRootComponent when done
preRenderSetup(renderRootComponent);
});