Skip to content

Commit bf01b97

Browse files
authored
Merge pull request #1109 from opencrvs/fix/slow-connection-error
fix: run assignment within IIFE
2 parents d94c555 + 1904216 commit bf01b97

File tree

2 files changed

+73
-46
lines changed

2 files changed

+73
-46
lines changed

src/client-config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
*
99
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
1010
*/
11+
12+
/**
13+
* When running application in slow network condition (reproducible using 3G), the client-config.js might be loaded twice.
14+
* This results to issues like `Uncaught SyntaxError: "identifier scheme has already been declared at (client-config.js:1:1")`.
15+
*
16+
* On high level, refreshing the browser window requests new document page. The document page includes script tag to load client-config.js.
17+
* If the network is slow, the browser might start loading and executing client-config.js again before the previous one is torn down, causing the error.
18+
*
19+
*/
20+
;(function initClientConfig() {
21+
1122
window.config = {
1223
API_GATEWAY_URL: 'http://localhost:7070/',
1324
CONFIG_API_URL: 'http://localhost:2021',
@@ -32,8 +43,11 @@ window.config = {
3243
url: 'http://localhost:3040/ping',
3344
}
3445
],
46+
// NOTE: This is not valid javascript until replaced during build time.
47+
// IIFE just reveals it.
3548
FEATURES: {
3649
// The V2_EVENTS variable is passed down from src/index.ts:309
3750
V2_EVENTS: {{ V2_EVENTS }}
3851
}
3952
}
53+
})()

src/client-config.prod.js

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,67 @@
88
*
99
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
1010
*/
11-
const scheme = window.location.protocol // "http:" or "https:"
12-
const hostname = '{{hostname}}' // Replace dynamically if needed
13-
const sentry = '{{sentry}}' // Replace dynamically if needed
1411

15-
window.config = {
16-
API_GATEWAY_URL: `${scheme}//gateway.${hostname}/`,
17-
CONFIG_API_URL: `${scheme}//config.${hostname}`,
18-
LOGIN_URL: `${scheme}//login.${hostname}`,
19-
AUTH_URL: `${scheme}//gateway.${hostname}/auth/`,
20-
MINIO_URL: `${scheme}//minio.${hostname}/ocrvs/`,
21-
MINIO_BASE_URL: `${scheme}//minio.${hostname}`, // URL without path/bucket information, used for file uploads, v2
22-
MINIO_BUCKET: 'ocrvs',
23-
COUNTRY_CONFIG_URL: `${scheme}//countryconfig.${hostname}`,
24-
// Country code in uppercase ALPHA-3 format
25-
COUNTRY: 'FAR',
26-
LANGUAGES: 'en,fr',
27-
SENTRY: sentry,
28-
DASHBOARDS: [
29-
{
30-
id: 'registrations',
31-
title: {
32-
id: 'dashboard.registrationsTitle',
33-
defaultMessage: 'Registrations Dashboard',
34-
description: 'Menu item for registrations dashboard'
35-
},
36-
url: `${scheme}//metabase.${hostname}/public/dashboard/03be04d6-bde0-4fa7-9141-21cea2a7518b#bordered=false&titled=false&refresh=300`, // Filled in below
37-
},
38-
{
39-
id: 'completeness',
40-
title: {
41-
id: 'dashboard.completenessTitle',
42-
defaultMessage: 'Completeness Dashboard',
43-
description: 'Menu item for completeness dashboard'
12+
/**
13+
* When running application in slow network condition (reproducible using 3G), the client-config.js might be loaded twice.
14+
* This results to issues like `Uncaught SyntaxError: "identifier scheme has already been declared at (client-config.js:1:1")`.
15+
*
16+
* On high level, refreshing the browser window requests new document page. The document page includes script tag to load client-config.js.
17+
* If the network is slow, the browser might start loading and executing client-config.js again before the previous one is torn down, causing the error.
18+
*
19+
*/
20+
;(function initClientConfig() {
21+
const scheme = window.location.protocol // "http:" or "https:"
22+
const hostname = '{{hostname}}' // Replaced dynamically
23+
const sentry = '{{sentry}}' // Replaced dynamically
24+
25+
window.config = {
26+
API_GATEWAY_URL: `${scheme}//gateway.${hostname}/`,
27+
CONFIG_API_URL: `${scheme}//config.${hostname}`,
28+
LOGIN_URL: `${scheme}//login.${hostname}`,
29+
AUTH_URL: `${scheme}//gateway.${hostname}/auth/`,
30+
MINIO_URL: `${scheme}//minio.${hostname}/ocrvs/`,
31+
MINIO_BASE_URL: `${scheme}//minio.${hostname}`, // URL without path/bucket information, used for file uploads, v2
32+
MINIO_BUCKET: 'ocrvs',
33+
COUNTRY_CONFIG_URL: `${scheme}//countryconfig.${hostname}`,
34+
// Country code in uppercase ALPHA-3 format
35+
COUNTRY: 'FAR',
36+
LANGUAGES: 'en,fr',
37+
SENTRY: sentry,
38+
DASHBOARDS: [
39+
{
40+
id: 'registrations',
41+
title: {
42+
id: 'dashboard.registrationsTitle',
43+
defaultMessage: 'Registrations Dashboard',
44+
description: 'Menu item for registrations dashboard'
45+
},
46+
url: `${scheme}//metabase.${hostname}/public/dashboard/03be04d6-bde0-4fa7-9141-21cea2a7518b#bordered=false&titled=false&refresh=300`
4447
},
45-
url: `${scheme}//metabase.${hostname}/public/dashboard/41940907-8542-4e18-a05d-2408e7e9838a#bordered=false&titled=false&refresh=300`,
46-
},
47-
{
48-
id: 'registry',
49-
title: {
50-
id: 'dashboard.registryTitle',
51-
defaultMessage: 'Registry',
52-
description: 'Menu item for registry dashboard'
48+
{
49+
id: 'completeness',
50+
title: {
51+
id: 'dashboard.completenessTitle',
52+
defaultMessage: 'Completeness Dashboard',
53+
description: 'Menu item for completeness dashboard'
54+
},
55+
url: `${scheme}//metabase.${hostname}/public/dashboard/41940907-8542-4e18-a05d-2408e7e9838a#bordered=false&titled=false&refresh=300`
5356
},
54-
url: `${scheme}//metabase.${hostname}/public/dashboard/dc66b77a-79df-4f68-8fc8-5e5d5a2d7a35#bordered=false&titled=false&refresh=300`,
57+
{
58+
id: 'registry',
59+
title: {
60+
id: 'dashboard.registryTitle',
61+
defaultMessage: 'Registry',
62+
description: 'Menu item for registry dashboard'
63+
},
64+
url: `${scheme}//metabase.${hostname}/public/dashboard/dc66b77a-79df-4f68-8fc8-5e5d5a2d7a35#bordered=false&titled=false&refresh=300`
65+
}
66+
],
67+
// NOTE: This is not valid javascript until replaced during build time.
68+
// IIFE just reveals it.
69+
FEATURES: {
70+
// The V2_EVENTS variable is passed down from src/index.ts:309
71+
V2_EVENTS: {{ V2_EVENTS }}
5572
}
56-
],
57-
FEATURES: {
58-
// The V2_EVENTS variable is passed down from src/index.ts:309
59-
V2_EVENTS: {{ V2_EVENTS }}
6073
}
61-
}
74+
})()

0 commit comments

Comments
 (0)