Skip to content

Commit da8b5dc

Browse files
authored
fix: avoid using top-level await (#13607)
1 parent ee21412 commit da8b5dc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

.changeset/nervous-islands-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid using top-level await

packages/kit/src/runtime/app/server/event.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ let request_event = null;
66
/** @type {import('node:async_hooks').AsyncLocalStorage<RequestEvent | null>} */
77
let als;
88

9-
try {
10-
const hooks = await import('node:async_hooks');
11-
als = new hooks.AsyncLocalStorage();
12-
} catch {
13-
// can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
14-
// this isn't behind `supports` because it's basically just StackBlitz (i.e.
15-
// in-browser usage) that doesn't support it AFAICT
16-
}
9+
import('node:async_hooks')
10+
.then((hooks) => (als = new hooks.AsyncLocalStorage()))
11+
.catch(() => {
12+
// can't use AsyncLocalStorage, but can still call getRequestEvent synchronously.
13+
// this isn't behind `supports` because it's basically just StackBlitz (i.e.
14+
// in-browser usage) that doesn't support it AFAICT
15+
});
1716

1817
/**
1918
* Returns the current `RequestEvent`. Can be used inside `handle`, `load` and actions (and functions called by them).

0 commit comments

Comments
 (0)