@atlaspack/runtime-browser-hmr 2.14.5-dev.1c70d50f9.99 → 2.14.5-dev.69

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.
package/CHANGELOG.md CHANGED
@@ -1,39 +1,5 @@
1
1
  # @atlaspack/runtime-browser-hmr
2
2
 
3
- ## 2.14.14
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies []:
8
- - @atlaspack/utils@2.15.2
9
- - @atlaspack/plugin@2.14.14
10
-
11
- ## 2.14.13
12
-
13
- ### Patch Changes
14
-
15
- - [#633](https://github.com/atlassian-labs/atlaspack/pull/633) [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b) Thanks [@sbhuiyan-atlassian](https://github.com/sbhuiyan-atlassian)! - Ported various HMR changes from Parcel
16
-
17
- - Updated dependencies []:
18
- - @atlaspack/utils@2.15.1
19
- - @atlaspack/plugin@2.14.13
20
-
21
- ## 2.14.12
22
-
23
- ### Patch Changes
24
-
25
- - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
26
- - @atlaspack/utils@2.15.0
27
- - @atlaspack/plugin@2.14.12
28
-
29
- ## 2.14.11
30
-
31
- ### Patch Changes
32
-
33
- - Updated dependencies []:
34
- - @atlaspack/utils@2.14.11
35
- - @atlaspack/plugin@2.14.11
36
-
37
3
  ## 2.14.10
38
4
 
39
5
  ### Patch Changes
@@ -67,7 +67,7 @@ function Module(moduleName) {
67
67
  }
68
68
  module.bundle.Module = Module;
69
69
  module.bundle.hotData = {};
70
- var checkedAssets /*: {|[string]: boolean|} */, disposedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
70
+ var checkedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
71
71
 
72
72
  function getHostname() {
73
73
  return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
@@ -111,7 +111,6 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
111
111
  // $FlowFixMe
112
112
  ws.onmessage = async function (event /*: {data: string, ...} */) {
113
113
  checkedAssets = {} /*: {|[string]: boolean|} */;
114
- disposedAssets = {} /*: {|[string]: boolean|} */;
115
114
  assetsToAccept = [];
116
115
  assetsToDispose = [];
117
116
  var data /*: HMRMessage */ = JSON.parse(event.data);
@@ -136,10 +135,19 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
136
135
  window.dispatchEvent(new CustomEvent('parcelhmraccept'));
137
136
  }
138
137
  await hmrApplyUpdates(assets);
139
- hmrDisposeQueue();
138
+
139
+ // Dispose all old assets.
140
+ let processedAssets = {} /*: {|[string]: boolean|} */;
141
+ for (let i = 0; i < assetsToDispose.length; i++) {
142
+ let id = assetsToDispose[i][1];
143
+ if (!processedAssets[id]) {
144
+ hmrDispose(assetsToDispose[i][0], id);
145
+ processedAssets[id] = true;
146
+ }
147
+ }
140
148
 
141
149
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
142
- let processedAssets = {};
150
+ processedAssets = {};
143
151
  for (let i = 0; i < assetsToAccept.length; i++) {
144
152
  let id = assetsToAccept[i][1];
145
153
  if (!processedAssets[id]) {
@@ -377,11 +385,7 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
377
385
  // $FlowFixMe
378
386
  let fn = global.parcelHotUpdate[asset.id];
379
387
  modules[asset.id] = [fn, deps];
380
- }
381
-
382
- // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
383
- // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
384
- if (bundle.parent) {
388
+ } else if (bundle.parent) {
385
389
  hmrApply(bundle.parent, asset);
386
390
  }
387
391
  }
@@ -465,17 +469,6 @@ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsBy
465
469
  return true;
466
470
  }
467
471
  }
468
- function hmrDisposeQueue() {
469
- // Dispose all old assets.
470
- for (let i = 0; i < assetsToDispose.length; i++) {
471
- let id = assetsToDispose[i][1];
472
- if (!disposedAssets[id]) {
473
- hmrDispose(assetsToDispose[i][0], id);
474
- disposedAssets[id] = true;
475
- }
476
- }
477
- assetsToDispose = [];
478
- }
479
472
  function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
480
473
  var cached = bundle.cache[id];
481
474
  bundle.hotData[id] = {};
@@ -496,23 +489,18 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
496
489
  // Run the accept callbacks in the new version of the module.
497
490
  var cached = bundle.cache[id];
498
491
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
499
- let assetsToAlsoAccept = [];
500
492
  cached.hot._acceptCallbacks.forEach(function (cb) {
501
- let additionalAssets = cb(function () {
493
+ var assetsToAlsoAccept = cb(function () {
502
494
  return getParents(module.bundle.root, id);
503
495
  });
504
- if (Array.isArray(additionalAssets) && additionalAssets.length) {
505
- assetsToAlsoAccept.push(...additionalAssets);
496
+ if (assetsToAlsoAccept && assetsToAccept.length) {
497
+ assetsToAlsoAccept.forEach(function (a) {
498
+ hmrDispose(a[0], a[1]);
499
+ });
500
+
501
+ // $FlowFixMe[method-unbinding]
502
+ assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
506
503
  }
507
504
  });
508
- if (assetsToAlsoAccept.length > 0) {
509
- let handled = assetsToAlsoAccept.every(function (a) {
510
- return hmrAcceptCheck(a[0], a[1]);
511
- });
512
- if (!handled) {
513
- return fullReload();
514
- }
515
- hmrDisposeQueue();
516
- }
517
505
  }
518
506
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-browser-hmr",
3
- "version": "2.14.5-dev.1c70d50f9.99+1c70d50f9",
3
+ "version": "2.14.5-dev.69+67cb517ae",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,9 +15,9 @@
15
15
  "node": ">= 16.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.5-dev.1c70d50f9.99+1c70d50f9",
19
- "@atlaspack/utils": "2.14.5-dev.1c70d50f9.99+1c70d50f9"
18
+ "@atlaspack/plugin": "2.14.5-dev.69+67cb517ae",
19
+ "@atlaspack/utils": "2.14.5-dev.69+67cb517ae"
20
20
  },
21
21
  "type": "commonjs",
22
- "gitHead": "1c70d50f914cb662515b0b61053e51a06f3af234"
22
+ "gitHead": "67cb517ae793046fb5a0d2ef02ba74510fefccf3"
23
23
  }
@@ -72,7 +72,6 @@ module.bundle.Module = Module;
72
72
  module.bundle.hotData = {};
73
73
 
74
74
  var checkedAssets /*: {|[string]: boolean|} */,
75
- disposedAssets /*: {|[string]: boolean|} */,
76
75
  assetsToDispose /*: Array<[ParcelRequire, string]> */,
77
76
  assetsToAccept /*: Array<[ParcelRequire, string]> */;
78
77
 
@@ -135,7 +134,6 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
135
134
  // $FlowFixMe
136
135
  ws.onmessage = async function (event /*: {data: string, ...} */) {
137
136
  checkedAssets = ({} /*: {|[string]: boolean|} */);
138
- disposedAssets = ({} /*: {|[string]: boolean|} */);
139
137
  assetsToAccept = [];
140
138
  assetsToDispose = [];
141
139
 
@@ -175,10 +173,19 @@ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
175
173
 
176
174
  await hmrApplyUpdates(assets);
177
175
 
178
- hmrDisposeQueue();
176
+ // Dispose all old assets.
177
+ let processedAssets = ({} /*: {|[string]: boolean|} */);
178
+ for (let i = 0; i < assetsToDispose.length; i++) {
179
+ let id = assetsToDispose[i][1];
180
+
181
+ if (!processedAssets[id]) {
182
+ hmrDispose(assetsToDispose[i][0], id);
183
+ processedAssets[id] = true;
184
+ }
185
+ }
179
186
 
180
187
  // Run accept callbacks. This will also re-execute other disposed assets in topological order.
181
- let processedAssets = {};
188
+ processedAssets = {};
182
189
  for (let i = 0; i < assetsToAccept.length; i++) {
183
190
  let id = assetsToAccept[i][1];
184
191
 
@@ -486,11 +493,7 @@ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
486
493
  // $FlowFixMe
487
494
  let fn = global.parcelHotUpdate[asset.id];
488
495
  modules[asset.id] = [fn, deps];
489
- }
490
-
491
- // Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
492
- // This is required in case modules are duplicated. We need to ensure all instances have the updated code.
493
- if (bundle.parent) {
496
+ } else if (bundle.parent) {
494
497
  hmrApply(bundle.parent, asset);
495
498
  }
496
499
  }
@@ -594,20 +597,6 @@ function hmrAcceptCheckOne(
594
597
  }
595
598
  }
596
599
 
597
- function hmrDisposeQueue() {
598
- // Dispose all old assets.
599
- for (let i = 0; i < assetsToDispose.length; i++) {
600
- let id = assetsToDispose[i][1];
601
-
602
- if (!disposedAssets[id]) {
603
- hmrDispose(assetsToDispose[i][0], id);
604
- disposedAssets[id] = true;
605
- }
606
- }
607
-
608
- assetsToDispose = [];
609
- }
610
-
611
600
  function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
612
601
  var cached = bundle.cache[id];
613
602
  bundle.hotData[id] = {};
@@ -631,26 +620,18 @@ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
631
620
  // Run the accept callbacks in the new version of the module.
632
621
  var cached = bundle.cache[id];
633
622
  if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
634
- let assetsToAlsoAccept = [];
635
623
  cached.hot._acceptCallbacks.forEach(function (cb) {
636
- let additionalAssets = cb(function () {
624
+ var assetsToAlsoAccept = cb(function () {
637
625
  return getParents(module.bundle.root, id);
638
626
  });
639
- if (Array.isArray(additionalAssets) && additionalAssets.length) {
640
- assetsToAlsoAccept.push(...additionalAssets);
641
- }
642
- });
643
-
644
- if (assetsToAlsoAccept.length > 0) {
645
- let handled = assetsToAlsoAccept.every(function (a) {
646
- return hmrAcceptCheck(a[0], a[1]);
647
- });
627
+ if (assetsToAlsoAccept && assetsToAccept.length) {
628
+ assetsToAlsoAccept.forEach(function (a) {
629
+ hmrDispose(a[0], a[1]);
630
+ });
648
631
 
649
- if (!handled) {
650
- return fullReload();
632
+ // $FlowFixMe[method-unbinding]
633
+ assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
651
634
  }
652
-
653
- hmrDisposeQueue();
654
- }
635
+ });
655
636
  }
656
637
  }