@sourceregistry/sveltekit-enhance 2.0.4 → 2.0.5

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.
@@ -19,10 +19,14 @@ export class Deferred {
19
19
  this.reject = (reason) => {
20
20
  if (!this._isResolved && !this._isRejected) {
21
21
  this._isRejected = true;
22
+ this._rejectReason = reason;
22
23
  reject(reason);
23
24
  }
24
25
  };
25
26
  });
27
+ // Rejection is observable through isRejected/rejectReason; without a handler here a
28
+ // rejected Deferred nobody awaits would crash Node with an unhandled rejection.
29
+ this.promise.catch(() => { });
26
30
  }
27
31
  /**
28
32
  * Returns true if the promise has been resolved
@@ -58,7 +62,6 @@ export class Deferred {
58
62
  return r;
59
63
  },
60
64
  (reason) => {
61
- this._rejectReason = reason;
62
65
  this.reject(reason);
63
66
  return reason;
64
67
  }
package/dist/index.js CHANGED
@@ -77,7 +77,7 @@ export const load = (load, ...contexts) => {
77
77
  }
78
78
  }
79
79
  try {
80
- return load(Object.assign(contextInput, { context: combined }));
80
+ return await load(Object.assign(contextInput, { context: combined }));
81
81
  }
82
82
  catch (e) {
83
83
  return EnhanceErrorHandle(e, contextInput);
@@ -209,11 +209,15 @@ export const handle = (handle, ...contexts) => async (input) => {
209
209
  }
210
210
  };
211
211
  try {
212
- const response = await apply_handle(0, input.event);
212
+ let response = await apply_handle(0, input.event);
213
213
  const isSSE = response.headers.get('content-type')?.includes('text/event-stream');
214
214
  if (!isSSE && contextInput.responseHandlers.length > 0) {
215
215
  for (const responseHandler of contextInput.responseHandlers) {
216
- await responseHandler({ event: contextInput, response });
216
+ // Handlers may return a replacement Response (needed when headers are immutable,
217
+ // eg. Response.redirect() or a proxied fetch response).
218
+ const replacement = await responseHandler({ event: contextInput, response });
219
+ if (replacement instanceof Response)
220
+ response = replacement;
217
221
  }
218
222
  }
219
223
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/sveltekit-enhance",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Composable enhance and form utilities for SvelteKit actions, loads, methods, and hooks.",
5
5
  "author": "A.P.A. Slaa (a.p.a.slaa@projectsource.nl)",
6
6
  "engines": {