@atlaspack/runtime-js 2.12.1-canary.3603 → 2.12.1-canary.3605

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,42 +9,92 @@ function load() {
9
9
  }
10
10
  function _load() {
11
11
  _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
12
- var url;
13
- return _regeneratorRuntime().wrap(function _callee$(_context) {
14
- while (1) switch (_context.prev = _context.next) {
12
+ var url, maxRetries, _loop, _ret, i;
13
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
14
+ while (1) switch (_context2.prev = _context2.next) {
15
15
  case 0:
16
- if (!parcelRequire.retryState) {
17
- parcelRequire.retryState = {};
18
- }
19
- if (globalThis.navigator.onLine) {
20
- _context.next = 4;
21
- break;
22
- }
23
- _context.next = 4;
24
- return new Promise(function (res) {
25
- return globalThis.addEventListener('online', res, {
26
- once: true
27
- });
16
+ url = require('../bundle-manifest').resolve(id);
17
+ maxRetries = 6;
18
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
19
+ var requestUrl, jitter, delay;
20
+ return _regeneratorRuntime().wrap(function _loop$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ if (globalThis.navigator.onLine) {
24
+ _context.next = 3;
25
+ break;
26
+ }
27
+ _context.next = 3;
28
+ return new Promise(function (resolve) {
29
+ return globalThis.addEventListener('online', resolve, {
30
+ once: true
31
+ });
32
+ });
33
+ case 3:
34
+ requestUrl = url;
35
+ if (i !== 0) {
36
+ // Date ensures the client hasn't previously cached a failed request
37
+ requestUrl = "".concat(requestUrl, "?retry=").concat(i, ":").concat(Date.now());
38
+ }
39
+ _context.prev = 5;
40
+ _context.next = 8;
41
+ return __parcel__import__(requestUrl);
42
+ case 8:
43
+ _context.t0 = _context.sent;
44
+ return _context.abrupt("return", {
45
+ v: _context.t0
46
+ });
47
+ case 12:
48
+ _context.prev = 12;
49
+ _context.t1 = _context["catch"](5);
50
+ if (!(i === maxRetries)) {
51
+ _context.next = 16;
52
+ break;
53
+ }
54
+ throw _context.t1;
55
+ case 16:
56
+ // Dispatch event for reporting
57
+ window.dispatchEvent(new CustomEvent('atlaspack:import_retry', {
58
+ detail: {
59
+ target: url,
60
+ attempt: i
61
+ }
62
+ }));
63
+ jitter = Math.round(Math.random() * 100);
64
+ delay = Math.min(Math.pow(2, i), 8) * 1000;
65
+ _context.next = 21;
66
+ return new Promise(function (resolve) {
67
+ return setTimeout(resolve, delay + jitter);
68
+ });
69
+ case 21:
70
+ case "end":
71
+ return _context.stop();
72
+ }
73
+ }, _loop, null, [[5, 12]]);
28
74
  });
75
+ i = 1;
29
76
  case 4:
30
- url = require('../bundle-manifest').resolve(id);
31
- if (parcelRequire.retryState[id] != undefined) {
32
- url = "".concat(url, "?retry=").concat(parcelRequire.retryState[id]);
77
+ if (!(i <= maxRetries)) {
78
+ _context2.next = 12;
79
+ break;
80
+ }
81
+ return _context2.delegateYield(_loop(), "t0", 6);
82
+ case 6:
83
+ _ret = _context2.t0;
84
+ if (!_ret) {
85
+ _context2.next = 9;
86
+ break;
33
87
  }
34
- _context.prev = 6;
35
- _context.next = 9;
36
- return __parcel__import__(url);
88
+ return _context2.abrupt("return", _ret.v);
37
89
  case 9:
38
- return _context.abrupt("return", _context.sent);
90
+ i++;
91
+ _context2.next = 4;
92
+ break;
39
93
  case 12:
40
- _context.prev = 12;
41
- _context.t0 = _context["catch"](6);
42
- parcelRequire.retryState[id] = Date.now();
43
- case 15:
44
94
  case "end":
45
- return _context.stop();
95
+ return _context2.stop();
46
96
  }
47
- }, _callee, null, [[6, 12]]);
97
+ }, _callee);
48
98
  }));
49
99
  return _load.apply(this, arguments);
50
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-js",
3
- "version": "2.12.1-canary.3603+7e9e0e6a8",
3
+ "version": "2.12.1-canary.3605+c3c25718d",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,16 +12,16 @@
12
12
  "main": "lib/JSRuntime.js",
13
13
  "source": "src/JSRuntime.js",
14
14
  "engines": {
15
- "atlaspack": "2.12.1-canary.3603+7e9e0e6a8",
15
+ "atlaspack": "2.12.1-canary.3605+c3c25718d",
16
16
  "node": ">= 16.0.0"
17
17
  },
18
18
  "dependencies": {
19
- "@atlaspack/diagnostic": "2.12.1-canary.3603+7e9e0e6a8",
20
- "@atlaspack/domain-sharding": "2.12.1-canary.3603+7e9e0e6a8",
21
- "@atlaspack/feature-flags": "2.12.1-canary.3603+7e9e0e6a8",
22
- "@atlaspack/plugin": "2.12.1-canary.3603+7e9e0e6a8",
23
- "@atlaspack/utils": "2.12.1-canary.3603+7e9e0e6a8",
19
+ "@atlaspack/diagnostic": "2.12.1-canary.3605+c3c25718d",
20
+ "@atlaspack/domain-sharding": "2.12.1-canary.3605+c3c25718d",
21
+ "@atlaspack/feature-flags": "2.12.1-canary.3605+c3c25718d",
22
+ "@atlaspack/plugin": "2.12.1-canary.3605+c3c25718d",
23
+ "@atlaspack/utils": "2.12.1-canary.3605+c3c25718d",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
- "gitHead": "7e9e0e6a8614f7f5da8d7fa7da471395f65bd81a"
26
+ "gitHead": "c3c25718d9e8e63323d574e2ad26367251b1d46b"
27
27
  }
@@ -1,25 +1,41 @@
1
1
  async function load(id) {
2
- if (!parcelRequire.retryState) {
3
- parcelRequire.retryState = {};
4
- }
2
+ const url = require('../bundle-manifest').resolve(id);
5
3
 
6
- if (!globalThis.navigator.onLine) {
7
- await new Promise((res) =>
8
- globalThis.addEventListener('online', res, {once: true}),
9
- );
10
- }
4
+ const maxRetries = 6;
11
5
 
12
- let url = require('../bundle-manifest').resolve(id);
6
+ for (let i = 1; i <= maxRetries; i++) {
7
+ // Wait for the user to go online before making a request
8
+ if (!globalThis.navigator.onLine) {
9
+ await new Promise((resolve) =>
10
+ globalThis.addEventListener('online', resolve, {once: true}),
11
+ );
12
+ }
13
13
 
14
- if (parcelRequire.retryState[id] != undefined) {
15
- url = `${url}?retry=${parcelRequire.retryState[id]}`;
16
- }
14
+ let requestUrl = url;
15
+ if (i !== 0) {
16
+ // Date ensures the client hasn't previously cached a failed request
17
+ requestUrl = `${requestUrl}?retry=${i}:${Date.now()}`;
18
+ }
19
+
20
+ try {
21
+ // eslint-disable-next-line no-undef
22
+ return await __parcel__import__(requestUrl);
23
+ } catch (error) {
24
+ if (i === maxRetries) throw error;
25
+ // Dispatch event for reporting
26
+ window.dispatchEvent(
27
+ new CustomEvent('atlaspack:import_retry', {
28
+ detail: {
29
+ target: url,
30
+ attempt: i,
31
+ },
32
+ }),
33
+ );
34
+ const jitter = Math.round(Math.random() * 100);
35
+ const delay = Math.min(Math.pow(2, i), 8) * 1000;
17
36
 
18
- try {
19
- // eslint-disable-next-line no-undef
20
- return await __parcel__import__(url);
21
- } catch (error) {
22
- parcelRequire.retryState[id] = Date.now();
37
+ await new Promise((resolve) => setTimeout(resolve, delay + jitter));
38
+ }
23
39
  }
24
40
  }
25
41