dsh-unlag 1.9.24 → 1.9.25

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.
Files changed (2) hide show
  1. package/index.js +26 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -893,14 +893,34 @@ function currentBundleUrls(graph, request) {
893
893
  */
894
894
  async function fetchBundleAt(clientModules, url, method) {
895
895
  const address = `http://unlag.invalid${url}`
896
- if (typeof Request === 'function') {
897
- try {
898
- return await clientModules.fetchBundle(new Request(address, { method, headers: {} }))
899
- } catch (error) {
900
- if (error?.name !== 'TypeError') throw error
896
+ /**
897
+ * A table that accepts the question and then never answers would hold the request that asked it:
898
+ * the document waits on this script and the page stops. The wait is bounded, and a table that
899
+ * misses it is answered the same way as one that fails.
900
+ */
901
+ const limit = Number(process.env.DSH_UNLAG_FETCH_TIMEOUT_MS ?? '') > 0 ? Number(process.env.DSH_UNLAG_FETCH_TIMEOUT_MS) : 8000
902
+ let timer = null
903
+ const late = new Promise((_, reject) => {
904
+ timer = setTimeout(() => reject(new Error('the module table did not answer in time')), limit)
905
+ })
906
+ const asked = (async () => {
907
+ if (typeof Request === 'function') {
908
+ try {
909
+ return await clientModules.fetchBundle(new Request(address, { method, headers: {} }))
910
+ } catch (error) {
911
+ if (error?.name !== 'TypeError') throw error
912
+ }
901
913
  }
914
+ return clientModules.fetchBundle({ method, url: address })
915
+ })()
916
+ // Whichever side loses the race must still be observed, or its rejection ends the process.
917
+ asked.catch(() => {})
918
+ late.catch(() => {})
919
+ try {
920
+ return await Promise.race([asked, late])
921
+ } finally {
922
+ if (timer !== null) clearTimeout(timer)
902
923
  }
903
- return clientModules.fetchBundle({ method, url: address })
904
924
  }
905
925
 
906
926
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.24",
3
+ "version": "1.9.25",
4
4
  "type": "module",
5
5
  "description": "A press applies plugin edits right away and brings a laggy interface back; automatic reloading stays off unless you turn it on, so the press is the only trigger, and nothing restarts.",
6
6
  "license": "MIT",