Skip to content

Commit 1b1bcec

Browse files
committed
fix(app): unique prerender app id
1 parent c376140 commit 1b1bcec

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/runtime/internal/app.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,22 @@ import {
3030
} from "#nitro/virtual/feature-flags";
3131

3232
declare global {
33-
var __nitro__: NitroApp | undefined;
33+
var __nitro__:
34+
| Partial<
35+
Record<"default" | "prerender" | (string & {}), NitroApp | undefined>
36+
>
37+
| undefined;
3438
}
3539

36-
export function useNitroApp(): NitroApp {
37-
return (globalThis.__nitro__ ??= initNitroApp());
40+
const APP_ID = import.meta.prerender ? "prerender" : "default";
41+
42+
export function useNitroApp(_id = APP_ID): NitroApp {
43+
globalThis.__nitro__ ??= {};
44+
return (globalThis.__nitro__[_id] ??= initNitroApp());
3845
}
3946

40-
export function useNitroHooks(): HookableCore<NitroRuntimeHooks> {
41-
const nitroApp = useNitroApp();
47+
export function useNitroHooks(_id = APP_ID): HookableCore<NitroRuntimeHooks> {
48+
const nitroApp = useNitroApp(_id);
4249
const hooks = nitroApp.hooks;
4350
if (hooks) {
4451
return hooks;

src/runtime/nitro.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export function serverFetch(
2020
init?: RequestInit,
2121
context?: ServerRequestContext | H3EventContext
2222
): Promise<Response> {
23-
const nitro = globalThis.__nitro__ || globalThis.__nitro_builder__;
23+
const nitro =
24+
globalThis.__nitro__?.default ||
25+
globalThis.__nitro__?.prerender ||
26+
globalThis.__nitro_builder__;
2427
if (!nitro) {
2528
return Promise.reject(new Error("Nitro instance is not available."));
2629
}

0 commit comments

Comments
 (0)