forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.jsx
80 lines (70 loc) · 2.54 KB
/
root.jsx
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
79
80
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import ReactDOM from 'react-dom';
import {Provider} from 'react-redux';
import {Router, Route} from 'react-router-dom';
// Import our styles
import 'bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css';
import 'sass/styles.scss';
import 'katex/dist/katex.min.css';
import {browserHistory} from 'utils/browser_history';
import {makeAsyncComponent} from 'components/async_load';
import store from 'stores/redux_store.jsx';
import loadRoot from 'bundle-loader?lazy!components/root.jsx';
const Root = makeAsyncComponent(loadRoot);
// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup(callwhendone) {
window.onerror = (msg, url, line, column, stack) => {
var l = {};
l.level = 'ERROR';
l.message = 'msg: ' + msg + ' row: ' + line + ' col: ' + column + ' stack: ' + stack + ' url: ' + url;
const req = new XMLHttpRequest();
req.open('POST', '/api/v3/general/log_client');
req.setRequestHeader('Content-Type', 'application/json');
req.send(JSON.stringify(l));
if (window.mm_config && window.mm_config.EnableDeveloper === 'true') {
window.ErrorStore.storeLastError({type: 'developer', message: 'DEVELOPER MODE: A JavaScript error has occurred. Please use the JavaScript console to capture and report the error (row: ' + line + ' col: ' + column + ').'});
window.ErrorStore.emitChange();
}
};
callwhendone();
}
function renderRootComponent() {
ReactDOM.render((
<Provider store={store}>
<Router history={browserHistory}>
<Route
path='/'
component={Root}
/>
</Router>
</Provider>
),
document.getElementById('root'));
}
/**
* Adds a function to be invoked onload appended to any existing onload
* event handlers.
*
* @param {function} fn onload event handler
*
*/
function appendOnLoadEvent(fn) {
if (window.attachEvent) {
window.attachEvent('onload', fn);
} else if (window.onload) {
const curronload = window.onload;
window.onload = (evt) => {
curronload(evt);
fn(evt);
};
} else {
window.onload = fn;
}
}
appendOnLoadEvent(() => {
// Do the pre-render setup and call renderRootComponent when done
preRenderSetup(renderRootComponent);
});