rwsdk 1.0.0-beta.9-test.20251007155132 → 1.0.0-beta.9-test.20251008035247
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.
|
@@ -2,7 +2,6 @@ import { DefaultAppContext, RequestInfo } from "./types";
|
|
|
2
2
|
type DefaultRequestInfo = RequestInfo<DefaultAppContext>;
|
|
3
3
|
export declare const requestInfo: DefaultRequestInfo;
|
|
4
4
|
export declare function getRequestInfo(): RequestInfo;
|
|
5
|
-
export declare function waitForRequestInfo(): Promise<DefaultRequestInfo>;
|
|
6
5
|
export declare function runWithRequestInfo<Result>(nextRequestInfo: DefaultRequestInfo, fn: () => Result): Result;
|
|
7
6
|
export declare function runWithRequestInfoOverrides<Result>(overrides: Partial<DefaultRequestInfo>, fn: () => Result): Result;
|
|
8
7
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
-
const requestInfoDeferred = Promise.withResolvers();
|
|
3
2
|
const requestInfoStore = new AsyncLocalStorage();
|
|
4
3
|
const requestInfoBase = {};
|
|
5
4
|
const REQUEST_INFO_KEYS = [
|
|
@@ -17,7 +16,27 @@ REQUEST_INFO_KEYS.forEach((key) => {
|
|
|
17
16
|
configurable: false,
|
|
18
17
|
get: function () {
|
|
19
18
|
const store = requestInfoStore.getStore();
|
|
20
|
-
|
|
19
|
+
if (store) {
|
|
20
|
+
return store[key];
|
|
21
|
+
}
|
|
22
|
+
// context(justinvdm, 2025-10-08): During a chaotic HMR update, the async
|
|
23
|
+
// context (store) can be torn down while a request is in-flight. If this
|
|
24
|
+
// happens, we return an empty object for context properties instead of
|
|
25
|
+
// undefined. This prevents a hard crash when middleware (like setupDb)
|
|
26
|
+
// tries to set a property on the context of an already-orphaned request.
|
|
27
|
+
if (key === "ctx" || key === "__userContext") {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
},
|
|
32
|
+
set: function (value) {
|
|
33
|
+
const store = requestInfoStore.getStore();
|
|
34
|
+
// context(justinvdm, 2025-10-08): Only set the value if the store exists.
|
|
35
|
+
// If it doesn't, this is a no-op, which is the desired behavior for an
|
|
36
|
+
// orphaned request.
|
|
37
|
+
if (store) {
|
|
38
|
+
store[key] = value;
|
|
39
|
+
}
|
|
21
40
|
},
|
|
22
41
|
});
|
|
23
42
|
});
|
|
@@ -29,15 +48,8 @@ export function getRequestInfo() {
|
|
|
29
48
|
}
|
|
30
49
|
return store;
|
|
31
50
|
}
|
|
32
|
-
export function waitForRequestInfo() {
|
|
33
|
-
return requestInfoDeferred.promise;
|
|
34
|
-
}
|
|
35
51
|
export function runWithRequestInfo(nextRequestInfo, fn) {
|
|
36
|
-
|
|
37
|
-
requestInfoDeferred.resolve(nextRequestInfo);
|
|
38
|
-
return fn();
|
|
39
|
-
};
|
|
40
|
-
return requestInfoStore.run(nextRequestInfo, runWithRequestInfoFn);
|
|
52
|
+
return requestInfoStore.run(nextRequestInfo, fn);
|
|
41
53
|
}
|
|
42
54
|
export function runWithRequestInfoOverrides(overrides, fn) {
|
|
43
55
|
const requestInfo = requestInfoStore.getStore();
|
package/package.json
CHANGED