dsh-unlag 1.9.53 → 1.9.54

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 +24 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1336,10 +1336,33 @@ function serveBundlesAtCurrentRevision(ctx) {
1336
1336
  * be sent; so the pieces are kept with the body and the socket stays untouched.
1337
1337
  */
1338
1338
  const realWrite = res.write
1339
+ // A held answer still owes the caller the callbacks it passed: dropping one would leave a
1340
+ // handler that waits for the flush awaiting forever, and the fallback answer would never
1341
+ // run. They are answered on the next turn once the held body is collected.
1342
+ const answerCallback = (args) => {
1343
+ for (let at = args.length - 1; at >= 0; at -= 1) {
1344
+ if (typeof args[at] === 'function') {
1345
+ const done = args[at]
1346
+ try {
1347
+ process.nextTick(() => {
1348
+ try {
1349
+ done()
1350
+ } catch {
1351
+ /* the caller's own callback failed; the document still needs its script */
1352
+ }
1353
+ })
1354
+ } catch {
1355
+ /* no event loop to defer on; the answer matters more than the callback */
1356
+ }
1357
+ return
1358
+ }
1359
+ }
1360
+ }
1339
1361
  if (typeof realWrite === 'function') {
1340
1362
  res.write = (chunk, ...rest) => {
1341
1363
  if (held !== null) {
1342
1364
  if (typeof chunk === 'string' || Buffer.isBuffer(chunk)) parts.push(Buffer.from(chunk))
1365
+ answerCallback(rest)
1343
1366
  return true
1344
1367
  }
1345
1368
  return realWrite.call(res, chunk, ...rest)
@@ -1351,6 +1374,7 @@ function serveBundlesAtCurrentRevision(ctx) {
1351
1374
  const last = args[0]
1352
1375
  if (typeof last === 'string' || Buffer.isBuffer(last)) parts.push(Buffer.from(last))
1353
1376
  body = parts.length === 0 ? '' : Buffer.concat(parts)
1377
+ answerCallback(args)
1354
1378
  return res
1355
1379
  }
1356
1380
  return realEnd.apply(res, args)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unlag",
3
- "version": "1.9.53",
3
+ "version": "1.9.54",
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",