@jsenv/core 37.0.4 → 37.1.0

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.
@@ -51,20 +51,20 @@ const getDOMNodesUsingUrl = (urlToReload) => {
51
51
  }
52
52
  nodes.push({
53
53
  node,
54
- reload: () => {
54
+ reload: (hot) => {
55
55
  if (node.nodeName === "SCRIPT") {
56
56
  const copy = document.createElement("script");
57
57
  Array.from(node.attributes).forEach((attribute) => {
58
58
  copy.setAttribute(attribute.nodeName, attribute.nodeValue);
59
59
  });
60
- copy.src = injectQuery(node.src, { hot: Date.now() });
60
+ copy.src = injectQuery(node.src, { hot });
61
61
  if (node.parentNode) {
62
62
  node.parentNode.replaceChild(copy, node);
63
63
  } else {
64
64
  document.body.appendChild(copy);
65
65
  }
66
66
  } else {
67
- node[attributeName] = injectQuery(attribute, { hot: Date.now() });
67
+ node[attributeName] = injectQuery(attribute, { hot });
68
68
  }
69
69
  },
70
70
  });
@@ -108,16 +108,19 @@ const getDOMNodesUsingUrl = (urlToReload) => {
108
108
  visitNodeAttributeAsUrl(img, "src");
109
109
  const srcset = img.srcset;
110
110
  if (srcset) {
111
- const srcCandidates = parseSrcSet(srcset);
112
- srcCandidates.forEach((srcCandidate) => {
113
- const url = new URL(srcCandidate.specifier, `${window.location.href}`);
114
- if (shouldReloadUrl(url)) {
115
- srcCandidate.specifier = injectQuery(url, { hot: Date.now() });
116
- }
117
- });
118
111
  nodes.push({
119
112
  node: img,
120
- reload: () => {
113
+ reload: (hot) => {
114
+ const srcCandidates = parseSrcSet(srcset);
115
+ srcCandidates.forEach((srcCandidate) => {
116
+ const url = new URL(
117
+ srcCandidate.specifier,
118
+ `${window.location.href}`,
119
+ );
120
+ if (shouldReloadUrl(url)) {
121
+ srcCandidate.specifier = injectQuery(url, { hot });
122
+ }
123
+ });
121
124
  img.srcset = stringifySrcSet(srcCandidates);
122
125
  },
123
126
  });
@@ -137,8 +140,8 @@ const getDOMNodesUsingUrl = (urlToReload) => {
137
140
  return nodes;
138
141
  };
139
142
 
140
- const reloadJsImport = async (url) => {
141
- const urlWithHotSearchParam = injectQuery(url, { hot: Date.now() });
143
+ const reloadJsImport = async (url, hot) => {
144
+ const urlWithHotSearchParam = injectQuery(url, { hot });
142
145
  const namespace = await import(urlWithHotSearchParam);
143
146
  return namespace;
144
147
  };
@@ -264,7 +267,7 @@ const dequeue = async () => {
264
267
  }
265
268
  };
266
269
 
267
- const applyHotReload = async ({ hotInstructions }) => {
270
+ const applyHotReload = async ({ cause, hot, hotInstructions }) => {
268
271
  await hotInstructions.reduce(
269
272
  async (previous, { type, boundary, acceptedBy }) => {
270
273
  await previous;
@@ -280,7 +283,7 @@ const applyHotReload = async ({ hotInstructions }) => {
280
283
  delete urlHotMetas[urlToFetch];
281
284
  if (urlHotMeta.disposeCallback) {
282
285
  console.groupCollapsed(
283
- `[jsenv] cleanup ${boundary} (previously used in ${acceptedBy})`,
286
+ `[jsenv] cleanup ${boundary} (no longer referenced by ${acceptedBy})`,
284
287
  );
285
288
  console.log(`call dispose callback`);
286
289
  await urlHotMeta.disposeCallback();
@@ -291,10 +294,10 @@ const applyHotReload = async ({ hotInstructions }) => {
291
294
  }
292
295
 
293
296
  if (acceptedBy === boundary) {
294
- console.groupCollapsed(`[jsenv] hot reloading ${boundary}`);
297
+ console.groupCollapsed(`[jsenv] hot reloading ${boundary} (${cause})`);
295
298
  } else {
296
299
  console.groupCollapsed(
297
- `[jsenv] hot reloading ${acceptedBy} usage in ${boundary}`,
300
+ `[jsenv] hot reloading ${acceptedBy} usage in ${boundary} (${cause})`,
298
301
  );
299
302
  }
300
303
  if (type === "js_module") {
@@ -311,7 +314,7 @@ const applyHotReload = async ({ hotInstructions }) => {
311
314
  type: "dynamic_import",
312
315
  url: urlToFetch,
313
316
  };
314
- const namespace = await reloadJsImport(urlToFetch);
317
+ const namespace = await reloadJsImport(urlToFetch, hot);
315
318
  if (urlHotMeta.acceptCallback) {
316
319
  await urlHotMeta.acceptCallback(namespace);
317
320
  }
@@ -338,11 +341,11 @@ const applyHotReload = async ({ hotInstructions }) => {
338
341
  console.log(`no dom node using ${acceptedBy}`);
339
342
  } else if (domNodesCount === 1) {
340
343
  console.log(`reloading`, domNodesUsingUrl[0].node);
341
- domNodesUsingUrl[0].reload();
344
+ domNodesUsingUrl[0].reload(hot);
342
345
  } else {
343
346
  console.log(`reloading ${domNodesCount} nodes using ${acceptedBy}`);
344
347
  domNodesUsingUrl.forEach((domNodesUsingUrl) => {
345
- domNodesUsingUrl.reload();
348
+ domNodesUsingUrl.reload(hot);
346
349
  });
347
350
  }
348
351
  console.groupEnd();
@@ -75,7 +75,6 @@ const asUrlWithoutHotSearchParam = (url) => {
75
75
  const urlObject = new URL(url);
76
76
  if (urlObject.searchParams.has("hot")) {
77
77
  urlObject.searchParams.delete("hot");
78
- urlObject.searchParams.delete("v");
79
78
  return urlObject.href;
80
79
  }
81
80
  return url;