Skip to content

Commit 4c27f1d

Browse files
lbogdanSaraVieira
authored andcommitted
SSE loading screen updates. (codesandbox#2987)
1 parent c77caae commit 4c27f1d

File tree

4 files changed

+77
-32
lines changed

4 files changed

+77
-32
lines changed

standalone-packages/sse-loading-screen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"gsap": "^2.0.2",
1111
"preact": "^8.3.1",
1212
"preact-emotion": "^9.2.10",
13-
"socket.io-client": "^2.2.0",
13+
"socket.io-client": "^2.3.0",
1414
"xterm": "^3.5.1",
1515
"xterm-webfont": "^1.1.1"
1616
},

standalone-packages/sse-loading-screen/src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ body {
6868
box-sizing: border-box;
6969
max-width: 600px;
7070
width: 100%;
71-
font-size: 1.5rem;
71+
font-size: 1.3rem;
7272
font-weight: 200;
7373
display: flex;
7474
align-items: center;

standalone-packages/sse-loading-screen/src/index.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import { listenForPreviewSecret } from 'sandbox-hooks/preview-secret';
2020
import Cube from './Cube';
2121

2222
const SECOND = 1000; // ms
23+
const ERROR_COLOR = '#dc143c';
2324

2425
// without this line, CSSPlugin and AttrPlugin may get dropped by your bundler...
2526
// eslint-disable-next-line
2627
const plugins = [CSSPlugin, AttrPlugin];
2728

2829
let color;
30+
let error = false;
2931

3032
let hostParts;
3133
if (process.env.NODE_ENV === 'development') {
@@ -70,27 +72,37 @@ const createMainCube = () => {
7072

7173
const cubeTl = new TimelineLite({
7274
onComplete() {
73-
const clearerColor = color && color.clearer(0.4);
75+
let normalColor;
76+
let clearerColor;
77+
if (error) {
78+
normalColor = ERROR_COLOR;
79+
clearerColor = ERROR_COLOR;
80+
} else {
81+
normalColor = color && color();
82+
clearerColor = color && color.clearer(0.4)();
83+
}
7484
TweenLite.to(
7585
'.side',
7686
0.5,
7787
clearerColor
7888
? {
79-
boxShadow: `0 0 150px ${clearerColor()}`,
80-
backgroundColor: clearerColor(),
89+
boxShadow: `0 0 150px ${clearerColor}`,
90+
backgroundColor: clearerColor,
8191
}
8292
: {}
8393
);
8494
TweenLite.to(
8595
'#loading-progress',
8696
0.5,
87-
color
97+
normalColor
8898
? {
89-
backgroundColor: color(),
99+
backgroundColor: normalColor,
90100
}
91101
: {}
92102
);
93-
this.restart();
103+
if (!error) {
104+
this.restart();
105+
}
94106
},
95107
});
96108

@@ -177,6 +189,15 @@ const createMainCube = () => {
177189
// TweenLite.to('#fourth', 0.5, { x: 0, y: -66 });
178190
};
179191

192+
function updateStatusError(message) {
193+
error = true;
194+
const barTl = new TimelineLite();
195+
barTl
196+
.to('#loading-progress', 0.5, { width: '100%' })
197+
document.getElementById('loading-text').textContent = message;
198+
console.error(message);
199+
}
200+
180201
setTimeout(createMainCube, 500);
181202

182203
const NICE_TITLES = {
@@ -217,7 +238,9 @@ async function start() {
217238

218239
const socket = io(`https://${domain}`, {
219240
autoConnect: false,
220-
transports: ['websocket', 'polling'],
241+
transports: ['websocket'],
242+
reconnectionAttempts: 5,
243+
reconnectionDelayMax: 32000,
221244
});
222245

223246
socket.on('connect', () => {
@@ -237,7 +260,7 @@ async function start() {
237260

238261
socket.on('sandbox:error', ({ message, unrecoverable }) => {
239262
if (unrecoverable) {
240-
document.getElementById('loading-text').textContent = message;
263+
updateStatusError(message);
241264
socket.close();
242265
}
243266
});
@@ -296,11 +319,21 @@ async function start() {
296319

297320
window.addEventListener('resize', () => term.fit());
298321

322+
socket.on('reconnect_attempt', (attemptNumber) => {
323+
if (attemptNumber === 3) {
324+
socket.io.opts.transports = ['polling', 'websocket'];
325+
}
326+
});
327+
328+
socket.on('reconnect_failed', () => {
329+
updateStatusError('Failed to connect to containers service, please try again later');
330+
});
331+
299332
socket.connect();
300333
}
301334

302335
if (isLoop) {
303-
document.getElementById('loading-text').textContent = 'Error: Reloading too fast.';
336+
updateStatusError('Reloading too fast');
304337
} else {
305338
localStorage.setItem('last_loaded_at', now);
306339

standalone-packages/sse-loading-screen/yarn.lock

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,10 +1139,10 @@ bindings@~1.2.1:
11391139
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
11401140
integrity sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=
11411141

1142-
1143-
version "0.0.4"
1144-
resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.4.tgz#bcf13052ca54463f30f9fc7e95b9a47630a94921"
1145-
integrity sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=
1142+
1143+
version "0.0.5"
1144+
resolved "https://registry.yarnpkg.com/blob/-/blob-0.0.5.tgz#d680eeef25f8cd91ad533f5b01eed48e64caf683"
1145+
integrity sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig==
11461146

11471147
bluebird@^3.0.5:
11481148
version "3.5.1"
@@ -2018,6 +2018,13 @@ debug@~3.1.0:
20182018
dependencies:
20192019
ms "2.0.0"
20202020

2021+
debug@~4.1.0:
2022+
version "4.1.1"
2023+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
2024+
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
2025+
dependencies:
2026+
ms "^2.1.1"
2027+
20212028
decamelize@^1.1.2:
20222029
version "1.2.0"
20232030
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
@@ -2236,15 +2243,15 @@ encodeurl@~1.0.2:
22362243
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
22372244
integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=
22382245

2239-
engine.io-client@~3.3.1:
2240-
version "3.3.2"
2241-
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.3.2.tgz#04e068798d75beda14375a264bb3d742d7bc33aa"
2242-
integrity sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ==
2246+
engine.io-client@~3.4.0:
2247+
version "3.4.0"
2248+
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.4.0.tgz#82a642b42862a9b3f7a188f41776b2deab643700"
2249+
integrity sha512-a4J5QO2k99CM2a0b12IznnyQndoEvtA4UAldhGzKqnHf42I3Qs2W5SPnDvatZRcMaNZs4IevVicBPayxYt6FwA==
22432250
dependencies:
22442251
component-emitter "1.2.1"
22452252
component-inherit "0.0.3"
2246-
debug "~3.1.0"
2247-
engine.io-parser "~2.1.1"
2253+
debug "~4.1.0"
2254+
engine.io-parser "~2.2.0"
22482255
has-cors "1.1.0"
22492256
indexof "0.0.1"
22502257
parseqs "0.0.5"
@@ -2253,15 +2260,15 @@ engine.io-client@~3.3.1:
22532260
xmlhttprequest-ssl "~1.5.4"
22542261
yeast "0.1.2"
22552262

2256-
engine.io-parser@~2.1.1:
2257-
version "2.1.2"
2258-
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.1.2.tgz#4c0f4cff79aaeecbbdcfdea66a823c6085409196"
2259-
integrity sha512-dInLFzr80RijZ1rGpx1+56/uFoH7/7InhH3kZt+Ms6hT8tNx3NGW/WNSA/f8As1WkOfkuyb3tnRyuXGxusclMw==
2263+
engine.io-parser@~2.2.0:
2264+
version "2.2.0"
2265+
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.2.0.tgz#312c4894f57d52a02b420868da7b5c1c84af80ed"
2266+
integrity sha512-6I3qD9iUxotsC5HEMuuGsKA0cXerGz+4uGcXQEkfBidgKf0amsjrrtwcbwK/nzpZBxclXlV7gGl9dgWvu4LF6w==
22602267
dependencies:
22612268
after "0.8.2"
22622269
arraybuffer.slice "~0.0.7"
22632270
base64-arraybuffer "0.1.5"
2264-
blob "0.0.4"
2271+
blob "0.0.5"
22652272
has-binary2 "~1.0.2"
22662273

22672274
entities@^1.1.1, entities@~1.1.1:
@@ -3458,6 +3465,11 @@ [email protected]:
34583465
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
34593466
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
34603467

3468+
ms@^2.1.1:
3469+
version "2.1.2"
3470+
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
3471+
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
3472+
34613473
nan@^2.0.7, nan@^2.9.2:
34623474
version "2.10.0"
34633475
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
@@ -5097,17 +5109,17 @@ snapdragon@^0.8.1:
50975109
source-map-resolve "^0.5.0"
50985110
use "^3.1.0"
50995111

5100-
socket.io-client@^2.2.0:
5101-
version "2.2.0"
5102-
resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.2.0.tgz#84e73ee3c43d5020ccc1a258faeeb9aec2723af7"
5103-
integrity sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA==
5112+
socket.io-client@^2.3.0:
5113+
version "2.3.0"
5114+
resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.3.0.tgz#14d5ba2e00b9bcd145ae443ab96b3f86cbcc1bb4"
5115+
integrity sha512-cEQQf24gET3rfhxZ2jJ5xzAOo/xhZwK+mOqtGRg5IowZsMgwvHwnf/mCRapAAkadhM26y+iydgwsXGObBB5ZdA==
51045116
dependencies:
51055117
backo2 "1.0.2"
51065118
base64-arraybuffer "0.1.5"
51075119
component-bind "1.0.0"
51085120
component-emitter "1.2.1"
5109-
debug "~3.1.0"
5110-
engine.io-client "~3.3.1"
5121+
debug "~4.1.0"
5122+
engine.io-client "~3.4.0"
51115123
has-binary2 "~1.0.2"
51125124
has-cors "1.1.0"
51135125
indexof "0.0.1"

0 commit comments

Comments
 (0)