Skip to content

Commit a435367

Browse files
committed
Type fixes
1 parent 9ec5fb4 commit a435367

File tree

4 files changed

+64
-44
lines changed

4 files changed

+64
-44
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nextjs-cache-handler/src/handlers/cache-handler.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
Revalidate,
1616
} from "./cache-handler.types";
1717
import { PrerenderManifest } from "next/dist/build";
18-
import type {
19-
CachedFetchValue,
20-
IncrementalCachedPageValue,
21-
GetIncrementalResponseCacheContext,
22-
GetIncrementalFetchCacheContext,
18+
import {
19+
type CachedFetchValue,
20+
type IncrementalCachedPageValue,
21+
type GetIncrementalResponseCacheContext,
22+
type GetIncrementalFetchCacheContext,
23+
CachedRouteKind,
24+
IncrementalCacheValue,
2325
} from "next/dist/server/response-cache/types";
2426

2527
const PRERENDER_MANIFEST_VERSION = 4;
@@ -185,18 +187,23 @@ export class CacheHandler implements NextCacheHandler {
185187
);
186188
}
187189

190+
const value: IncrementalCacheValue &
191+
Pick<IncrementalCachedPageValue, "pageData"> = {
192+
kind: CachedRouteKind.APP_PAGE,
193+
html: pageHtmlFile,
194+
pageData,
195+
postponed: undefined,
196+
headers: undefined,
197+
status: undefined,
198+
rscData: undefined,
199+
segmentData: undefined,
200+
};
201+
188202
cacheHandlerValue = {
189203
lastModified: mtimeMs,
190204
lifespan: null,
191205
tags: [],
192-
value: {
193-
kind: "APP_PAGE" as unknown as any, // TODO check casting
194-
html: pageHtmlFile,
195-
pageData,
196-
postponed: undefined,
197-
headers: undefined,
198-
status: undefined,
199-
},
206+
value: value,
200207
};
201208
} catch (error) {
202209
cacheHandlerValue = null;
@@ -690,15 +697,15 @@ export class CacheHandler implements NextCacheHandler {
690697
lastModified,
691698
lifespan,
692699
tags: Object.freeze(cacheHandlerValueTags),
693-
value,
700+
value: value,
694701
};
695702

696703
await CacheHandler.#mergedHandler.set(cacheKey, cacheHandlerValue);
697704

698705
if (hasFallbackFalse && cacheHandlerValue.value?.kind === "APP_PAGE") {
699706
await CacheHandler.#writePagesRouterPage(
700707
cacheKey,
701-
cacheHandlerValue.value as unknown as IncrementalCachedPageValue, // TODO check casting
708+
cacheHandlerValue.value as unknown as IncrementalCachedPageValue,
702709
);
703710
}
704711
}

packages/nextjs-cache-handler/src/instrumentation/register-initial-cache.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import path from "node:path";
33
import { PRERENDER_MANIFEST, SERVER_DIRECTORY } from "next/constants";
44
import type { PrerenderManifest } from "next/dist/build";
55
import { CACHE_ONE_YEAR } from "next/dist/lib/constants";
6-
import { CachedFetchValue } from "next/dist/server/response-cache";
6+
import {
7+
CachedFetchValue,
8+
CachedRouteKind,
9+
CachedRouteValue,
10+
IncrementalCachedAppPageValue,
11+
IncrementalCachedPageValue,
12+
} from "next/dist/server/response-cache";
713
import type { OutgoingHttpHeaders } from "http";
814
import { getTagsFromHeaders } from "../helpers/getTagsFromHeaders";
915
import { Revalidate } from "../handlers/cache-handler.types";
@@ -197,20 +203,17 @@ export async function registerInitialCache(
197203
}
198204

199205
try {
200-
await cacheHandler.set(
201-
cachePath,
202-
{
203-
kind: "APP_ROUTE" as unknown as any, // TODO check casting
204-
body,
205-
headers: meta.headers,
206-
status: meta.status,
207-
},
208-
{
209-
revalidate,
210-
internal_lastModified: lastModified,
211-
tags: getTagsFromHeaders(meta.headers),
212-
},
213-
);
206+
const value: CachedRouteValue = {
207+
kind: CachedRouteKind.APP_ROUTE,
208+
body,
209+
headers: meta.headers,
210+
status: meta.status,
211+
};
212+
await cacheHandler.set(cachePath, value, {
213+
revalidate,
214+
internal_lastModified: lastModified,
215+
tags: getTagsFromHeaders(meta.headers),
216+
});
214217
} catch (error) {
215218
if (debug) {
216219
console.warn(
@@ -231,7 +234,7 @@ export async function registerInitialCache(
231234
revalidate: Revalidate,
232235
) {
233236
const isAppRouter = router === "app";
234-
237+
235238
if (isAppRouter && cachePath === "/") {
236239
cachePath = "/index";
237240
}
@@ -288,18 +291,22 @@ export async function registerInitialCache(
288291
}
289292

290293
try {
291-
await cacheHandler.set(
292-
cachePath,
293-
{
294-
kind: "APP_PAGE" as unknown as any, // TODO check casting
295-
html,
296-
pageData,
297-
postponed: meta?.postponed,
298-
headers: meta?.headers,
299-
status: meta?.status,
300-
},
301-
{ revalidate, internal_lastModified: lastModified },
302-
);
294+
const value: IncrementalCachedAppPageValue &
295+
Pick<IncrementalCachedPageValue, "pageData"> = {
296+
kind: CachedRouteKind.APP_PAGE,
297+
html,
298+
pageData,
299+
postponed: meta?.postponed,
300+
headers: meta?.headers,
301+
status: meta?.status,
302+
rscData: undefined,
303+
segmentData: undefined,
304+
};
305+
306+
await cacheHandler.set(cachePath, value, {
307+
revalidate,
308+
internal_lastModified: lastModified,
309+
});
303310
} catch (error) {
304311
if (debug) {
305312
console.warn(

packages/nextjs-cache-handler/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"declarationMap": true,
77
"esModuleInterop": true,
88
"incremental": false,
9-
"isolatedModules": true,
9+
"isolatedModules": false,
1010
"lib": ["es2022", "DOM", "DOM.Iterable"],
1111
"moduleDetection": "force",
1212
"noUncheckedIndexedAccess": true,

0 commit comments

Comments
 (0)