dsh-unlag 1.9.23 → 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 +37 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -85,6 +85,13 @@ const DEFAULT_ROOTS = [join(homedir(), '.dsh', 'plugins')]
85
85
  const MAX_DEFERRALS = 40
86
86
  const MAX_STARTUP_ROWS = 64
87
87
  const MAX_STARTUP_ROW_CHARS = 4096
88
+
89
+ /**
90
+ * The most plugin ids one bundle address may name. A real startup list is far below this; a made-up
91
+ * address far above it would otherwise have the plugin read one body per id, and answering a request
92
+ * is work the request itself must not be able to grow without bound.
93
+ */
94
+ const MAX_BUNDLE_IDS = 128
88
95
  const MIN_INTERVAL_MS = 1500
89
96
  /** The route the app publishes client bundles under; the same key the module table registers. */
90
97
  const BUNDLE_ROUTE = '/plugins'
@@ -848,8 +855,10 @@ function bundleRequest(rawUrl) {
848
855
  id = id.endsWith('/client.js') ? id.slice(0, -'/client.js'.length) : id
849
856
  if (id !== '') ids.push(id)
850
857
  }
851
- if (ids.length === 0) return null
852
- return { ids, sourceMap, rev: revAt < 0 ? '' : rest.slice(revAt + '&rev='.length) }
858
+ if (ids.length === 0 || ids.length > MAX_BUNDLE_IDS) return null
859
+ // The same plugin twice in one address is one plugin: read its body once.
860
+ const unique = [...new Set(ids)]
861
+ return { ids: unique, sourceMap, rev: revAt < 0 ? '' : rest.slice(revAt + '&rev='.length) }
853
862
  }
854
863
 
855
864
  /**
@@ -884,14 +893,34 @@ function currentBundleUrls(graph, request) {
884
893
  */
885
894
  async function fetchBundleAt(clientModules, url, method) {
886
895
  const address = `http://unlag.invalid${url}`
887
- if (typeof Request === 'function') {
888
- try {
889
- return await clientModules.fetchBundle(new Request(address, { method, headers: {} }))
890
- } catch (error) {
891
- 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
+ }
892
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)
893
923
  }
894
- return clientModules.fetchBundle({ method, url: address })
895
924
  }
896
925
 
897
926
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.23",
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",