@gigadrive/network-config 3.4.15 → 3.4.17

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.
@@ -8,16 +8,27 @@
8
8
  import { persistPprCacheEntry } from '__GIGADRIVE_PPR_RUNTIME__';
9
9
  import { AsyncLocalStorage } from 'node:async_hooks';
10
10
 
11
- globalThis.self ??= globalThis;
12
- globalThis.AsyncLocalStorage ??= AsyncLocalStorage;
13
- /* __GIGADRIVE_EDGE_IMPORTS__ */
14
- const registry = globalThis._ENTRIES;
15
- if (!registry) throw new Error('Next.js edge entry registry is unavailable');
16
- const entry = await registry['__GIGADRIVE_EDGE_ENTRY_KEY__'];
17
- const nextHandler = entry?.['__GIGADRIVE_EDGE_HANDLER_EXPORT__'];
18
- if (typeof nextHandler !== 'function') throw new Error('Next.js edge handler is unavailable');
11
+ // Next's edge chunks must evaluate lazily on the first request, not at module
12
+ // scope: chunk evaluation can block on runtime facilities that only exist once
13
+ // the guest server is up, and an eager top-level await would keep the process
14
+ // from ever reaching its listening state (observed as a MicroVM boot loop in
15
+ // prod). The promise is shared, so evaluation still happens exactly once.
16
+ let handlerPromise;
17
+ const resolveHandler = () =>
18
+ (handlerPromise ??= (async () => {
19
+ globalThis.self ??= globalThis;
20
+ globalThis.AsyncLocalStorage ??= AsyncLocalStorage;
21
+ /* __GIGADRIVE_EDGE_IMPORTS__ */
22
+ const registry = globalThis._ENTRIES;
23
+ if (!registry) throw new Error('Next.js edge entry registry is unavailable');
24
+ const entry = await registry['__GIGADRIVE_EDGE_ENTRY_KEY__'];
25
+ const handler = entry?.['__GIGADRIVE_EDGE_HANDLER_EXPORT__'];
26
+ if (typeof handler !== 'function') throw new Error('Next.js edge handler is unavailable');
27
+ return handler;
28
+ })());
19
29
 
20
30
  export async function fetch(request) {
31
+ const nextHandler = await resolveHandler();
21
32
  const pending = [];
22
33
  const url = new URL(request.url);
23
34
  const response = await nextHandler(request, {
@@ -14,18 +14,29 @@ import { fileURLToPath } from 'node:url';
14
14
  // invocations cannot race on process-global state.
15
15
  process.chdir(fileURLToPath(new URL('__GIGADRIVE_PROJECT_DIR__', import.meta.url)));
16
16
 
17
- const nextEntrypoint = await import('__GIGADRIVE_ENTRYPOINT__');
18
- // Turbopack builds may export the module (or its default) as a promise.
19
- const loadedEntrypoint = await Promise.resolve(nextEntrypoint.default ?? nextEntrypoint);
20
- const nextHandler =
21
- nextEntrypoint.handler ??
22
- loadedEntrypoint?.handler ??
23
- loadedEntrypoint?.default?.handler ??
24
- loadedEntrypoint?.default ??
25
- loadedEntrypoint;
26
- if (typeof nextHandler !== 'function') throw new Error('Next.js middleware handler is unavailable');
17
+ // The Next entrypoint must be imported lazily on the first request, not with a
18
+ // top-level await: some route module graphs block on facilities that only
19
+ // exist once the guest server is listening, and eager evaluation deadlocks the
20
+ // boot (observed as MicroVM boot loops in prod). The promise is shared, so the
21
+ // module still evaluates exactly once.
22
+ let handlerPromise;
23
+ const resolveHandler = () =>
24
+ (handlerPromise ??= (async () => {
25
+ const nextEntrypoint = await import('__GIGADRIVE_ENTRYPOINT__');
26
+ // Turbopack builds may export the module (or its default) as a promise.
27
+ const loadedEntrypoint = await Promise.resolve(nextEntrypoint.default ?? nextEntrypoint);
28
+ const handler =
29
+ nextEntrypoint.handler ??
30
+ loadedEntrypoint?.handler ??
31
+ loadedEntrypoint?.default?.handler ??
32
+ loadedEntrypoint?.default ??
33
+ loadedEntrypoint;
34
+ if (typeof handler !== 'function') throw new Error('Next.js middleware handler is unavailable');
35
+ return handler;
36
+ })());
27
37
 
28
38
  export async function fetch(request) {
39
+ const nextHandler = await resolveHandler();
29
40
  const pending = [];
30
41
  const url = new URL(request.url);
31
42
  const response = await nextHandler(request, {
@@ -15,18 +15,29 @@ import { fileURLToPath } from 'node:url';
15
15
  // invocations cannot race on process-global state.
16
16
  process.chdir(fileURLToPath(new URL('__GIGADRIVE_PROJECT_DIR__', import.meta.url)));
17
17
 
18
- const nextEntrypoint = await import('__GIGADRIVE_ENTRYPOINT__');
19
- // Turbopack builds may export the module (or its default) as a promise.
20
- const loadedEntrypoint = await Promise.resolve(nextEntrypoint.default ?? nextEntrypoint);
21
- const nextHandler =
22
- nextEntrypoint.handler ??
23
- loadedEntrypoint?.handler ??
24
- loadedEntrypoint?.default?.handler ??
25
- loadedEntrypoint?.default ??
26
- loadedEntrypoint;
27
- if (typeof nextHandler !== 'function') throw new Error('Next.js Node handler is unavailable');
18
+ // The Next entrypoint must be imported lazily on the first request, not with a
19
+ // top-level await: some route module graphs block on facilities that only
20
+ // exist once the guest server is listening, and eager evaluation deadlocks the
21
+ // boot (observed as MicroVM boot loops in prod). The promise is shared, so the
22
+ // module still evaluates exactly once.
23
+ let handlerPromise;
24
+ const resolveHandler = () =>
25
+ (handlerPromise ??= (async () => {
26
+ const nextEntrypoint = await import('__GIGADRIVE_ENTRYPOINT__');
27
+ // Turbopack builds may export the module (or its default) as a promise.
28
+ const loadedEntrypoint = await Promise.resolve(nextEntrypoint.default ?? nextEntrypoint);
29
+ const handler =
30
+ nextEntrypoint.handler ??
31
+ loadedEntrypoint?.handler ??
32
+ loadedEntrypoint?.default?.handler ??
33
+ loadedEntrypoint?.default ??
34
+ loadedEntrypoint;
35
+ if (typeof handler !== 'function') throw new Error('Next.js Node handler is unavailable');
36
+ return handler;
37
+ })());
28
38
 
29
39
  export default async function handler(req, res) {
40
+ const nextHandler = await resolveHandler();
30
41
  const pending = [];
31
42
  const hostname = Array.isArray(req.headers.host) ? req.headers.host[0] : req.headers.host;
32
43
  await nextHandler(req, res, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gigadrive/network-config",
3
- "version": "3.4.15",
3
+ "version": "3.4.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Gigadrive/sdk.git",