@@ -12,12 +12,12 @@ import AppData from './AppData.react';
12
12
import AppsIndex from './Apps/AppsIndex.react' ;
13
13
import AppsManager from 'lib/AppsManager' ;
14
14
import Browser from './Data/Browser/Browser.react' ;
15
- import CloudCode from './Data/CloudCode/B4ACloudCode.react' ;
15
+ // import CloudCode from './Data/CloudCode/B4ACloudCode.react';
16
16
import AppOverview from './Data/AppOverview/AppOverview.react' ;
17
17
import Config from './Data/Config/Config.react' ;
18
18
import FourOhFour from 'components/FourOhFour/FourOhFour.react' ;
19
19
import GeneralSettings from './Settings/GeneralSettings.react' ;
20
- import GraphQLConsole from './Data/ApiConsole/GraphQLConsole.react' ;
20
+ // import GraphQLConsole from './Data/ApiConsole/GraphQLConsole.react';
21
21
// import HostingSettings from './Settings/HostingSettings.react';
22
22
import HubConnections from './Hub/HubConnections.react' ;
23
23
import IndexManager from './IndexManager/IndexManager.react'
@@ -36,7 +36,7 @@ import { get } from 'lib/AJAX';
36
36
import { setBasePath } from 'lib/AJAX' ;
37
37
import ServerSettings from 'dashboard/ServerSettings/ServerSettings.react' ;
38
38
import { Helmet } from 'react-helmet' ;
39
- import Playground from './Data/Playground/Playground.react' ;
39
+ // import Playground from './Data/Playground/Playground.react';
40
40
import axios from 'lib/axios' ;
41
41
// import moment from 'moment';
42
42
import B4aConnectPage from './B4aConnectPage/B4aConnectPage.react' ;
@@ -49,7 +49,7 @@ import PushDetails from './Push/PushDetails.react';
49
49
import PushIndex from './Push/PushIndex.react' ;
50
50
import PushNew from './Push/PushNew.react' ;
51
51
// import PushSettings from './Settings/PushSettings.react';
52
- import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
52
+ import React , { useCallback , useEffect , useMemo , useState , Suspense , lazy } from 'react' ;
53
53
import RestConsole from './Data/ApiConsole/RestConsole.react' ;
54
54
// import SchemaOverview from './Data/Browser/SchemaOverview.react';
55
55
import SecuritySettings from './Settings/SecuritySettings.react' ;
@@ -66,6 +66,10 @@ import back4app2 from '../lib/back4app2';
66
66
import { initializeAmplitude } from 'lib/amplitudeEvents' ;
67
67
import { setUser as setSentryUser } from '@sentry/react' ;
68
68
69
+ const LazyGraphQLConsole = lazy ( ( ) => import ( './Data/ApiConsole/GraphQLConsole.react' ) ) ;
70
+ const LazyPlayground = lazy ( ( ) => import ( './Data/Playground/Playground.react' ) ) ;
71
+ const LazyCloudCode = lazy ( ( ) => import ( './Data/CloudCode/B4ACloudCode.react' ) ) ;
72
+
69
73
const ShowSchemaOverview = false ; //In progress features. Change false to true to work on this feature.
70
74
71
75
// class Empty extends React.Component {
@@ -150,6 +154,44 @@ const waitForScriptToLoad = async conditionFn => {
150
154
throw new Error ( 'Script not loaded yet!' ) ;
151
155
} ;
152
156
157
+ const preloadMap = {
158
+ cloudCode : ( ) => import ( './Data/CloudCode/B4ACloudCode.react' ) ,
159
+ graphqlConsole : ( ) => import ( './Data/ApiConsole/GraphQLConsole.react' ) ,
160
+ playground : ( ) => import ( './Data/Playground/Playground.react' ) ,
161
+ } ;
162
+
163
+ // Preload all routes with proper error handling and logging
164
+ const preloadRoute = async ( routeName , preloadFn ) => {
165
+ try {
166
+ await preloadFn ( ) ;
167
+ console . log ( `Successfully preloaded route: ${ routeName } ` ) ;
168
+ } catch ( err ) {
169
+ console . error ( `Error preloading route ${ routeName } :` , err ) ;
170
+ }
171
+ } ;
172
+
173
+ // Preload all routes in parallel
174
+ const preloadAllRoutes = ( ) => {
175
+ console . log ( 'Preloading routes...' ) ;
176
+ return Promise . all (
177
+ Object . entries ( preloadMap ) . map ( ( [ routeName , preloadFn ] ) =>
178
+ preloadRoute ( routeName , preloadFn )
179
+ )
180
+ ) ;
181
+ } ;
182
+
183
+ const LoadingComponent = ( ) => (
184
+ < div className = { baseStyles . center } style = { { background : '#0F1C32' } } >
185
+ < B4aLoader />
186
+ </ div >
187
+ ) ;
188
+
189
+ const LazyComponentWrapper = ( { children } ) => (
190
+ < Suspense fallback = { < LoadingComponent /> } >
191
+ { children }
192
+ </ Suspense >
193
+ ) ;
194
+
153
195
class Dashboard extends React . Component {
154
196
constructor ( props ) {
155
197
super ( ) ;
@@ -167,6 +209,11 @@ class Dashboard extends React.Component {
167
209
}
168
210
169
211
componentDidMount ( ) {
212
+ // Start preloading routes immediately but don't block on it
213
+ preloadAllRoutes ( ) . finally ( ( ) => {
214
+ console . log ( 'Route preloading complete' ) ;
215
+ } ) ;
216
+
170
217
get ( '/parse-dashboard-config.json' ) . then ( ( { apps, newFeaturesInLatestVersion = [ ] , user } ) => {
171
218
fetchHubUser ( ) . then ( userDetail => {
172
219
user . createdAt = userDetail . createdAt ;
@@ -390,8 +437,8 @@ class Dashboard extends React.Component {
390
437
const ApiConsoleRoute = (
391
438
< Route element = { < ApiConsole /> } >
392
439
< Route path = "rest" element = { < RestConsole /> } />
393
- < Route path = "graphql" element = { < GraphQLConsole / >} />
394
- < Route path = "js_console" element = { < Playground / >} />
440
+ < Route path = "graphql" element = { < LazyComponentWrapper > < LazyGraphQLConsole /> </ LazyComponentWrapper > } />
441
+ < Route path = "js_console" element = { < LazyComponentWrapper > < LazyPlayground /> </ LazyComponentWrapper > } />
395
442
< Route index element = { < Navigate replace to = "rest" /> } />
396
443
</ Route >
397
444
) ;
@@ -407,7 +454,7 @@ class Dashboard extends React.Component {
407
454
< Route path = "browser/:className" element = { < BrowserRoute /> } />
408
455
< Route path = "browser" element = { < BrowserRoute /> } />
409
456
410
- < Route path = "cloud_code" element = { < CloudCode / >} />
457
+ < Route path = "cloud_code" element = { < LazyComponentWrapper > < LazyCloudCode /> </ LazyComponentWrapper > } />
411
458
< Route path = "webhooks" element = { < Webhooks /> } />
412
459
413
460
< Route path = "jobs" > { JobsRoute } </ Route >
0 commit comments