-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expand file tree
/
Copy pathindex.jsx
More file actions
executable file
·100 lines (91 loc) · 3.62 KB
/
Copy pathindex.jsx
File metadata and controls
executable file
·100 lines (91 loc) · 3.62 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';
import { render } from 'react-dom';
import * as Sentry from '@sentry/react';
import { useLocation, useNavigationType, createRoutesFromChildren, matchRoutes } from 'react-router-dom';
import { appService } from '@/_services';
// RootRouter now handles route splitting for viewer isolation
import { RootRouter } from './RootRouter';
// eslint-disable-next-line import/no-unresolved
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import Backend from 'i18next-http-backend';
import config from 'config';
// When on a custom domain, use relative API path so requests go through the
// Cloudflare Worker proxy, making cookies first-party (fixes incognito sign-in).
// Compare hostnames (not origins) so local dev with different ports is unaffected.
try {
const apiHostname = new URL(config.apiUrl, window.location.origin).hostname;
if (apiHostname !== window.location.hostname) {
config.apiUrl = '/api';
}
} catch {
// apiUrl is already relative — no override needed
}
const AppWithProfiler = Sentry.withProfiler(RootRouter);
appService
.getConfig()
.then((config) => {
console.log({ config });
window.public_config = config;
const language = config.LANGUAGE || 'en';
const path = config?.SUB_PATH || '/';
i18n
.use(Backend)
.use(initReactI18next)
.init({
load: 'languageOnly',
fallbackLng: 'en',
lng: language,
backend: {
loadPath: `${path}assets/translations/{{lng}}.json`,
},
});
if (window.public_config.APM_VENDOR === 'sentry') {
const tooljetServerUrl = window.public_config.TOOLJET_SERVER_URL;
const tracingOrigins = ['localhost', /^\//];
const releaseVersion = window.public_config.RELEASE_VERSION
? `tooljet-${window.public_config.RELEASE_VERSION}`
: 'tooljet';
if (tooljetServerUrl) tracingOrigins.push(tooljetServerUrl);
Sentry.init({
dsn: window.public_config.SENTRY_DNS,
debug: !!window.public_config.SENTRY_DEBUG,
release: releaseVersion,
name: 'react',
integrations: [
new Sentry.BrowserTracing({
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
React.useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes
),
}),
],
tracesSampleRate: 0.5,
tracePropagationTargets: tracingOrigins,
});
}
})
.then(() => {
render(<AppWithProfiler />, document.getElementById('app'));
// .then(() => createRoot(document.getElementById('app')).render(<AppWithProfiler />));
// App booted successfully — clear reload flags from both recovery mechanisms
// (ChunkErrorBoundary in RootRouter.jsx and the .catch() below) so that
// future deployments can trigger auto-reload again if needed.
sessionStorage.removeItem('chunk_reload');
sessionStorage.removeItem('boot_reload');
})
.catch((error) => {
// If getConfig() or initialization fails (network error, auth redirect, stale response),
// React never mounts and the page stays stuck on the HTML loading spinner forever.
// Try one automatic reload to recover — the `boot_reload` flag prevents infinite loops.
console.error('App failed to initialize:', error);
if (!sessionStorage.getItem('boot_reload')) {
sessionStorage.setItem('boot_reload', 'true');
window.location.reload();
}
// If boot_reload flag is already set, we've already tried once.
// Don't reload again — the issue is likely persistent (server down, etc.).
});