Skip to content

Commit bab52f4

Browse files
committed
Fixed type conversions
1 parent 158cb08 commit bab52f4

File tree

4 files changed

+20
-27
lines changed

4 files changed

+20
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ if (process.env.NEXT_RUNTIME === "nodejs") {
8383

8484
## Installation
8585

86+
If you come from Next 14 or below, ensure to flush Redis cache before you run the project with this library. Cache format between Next 15 and Next <14 are not compatible!
87+
8688
## Next 15 Support and migration from `@neshca/cache-handler`
8789

8890
As `@neshca/cache-handler` does not officially support Next 15+ yet, we try to keep up with Next and prepare more or less temporary workarounds. At some point we will either create a fork of `@neshca/cache-handler` to fully support Next 15 or it gets updated by the maintainers. As for now we're building a set of decorators/workarounds you can use to build cache solutions for Next 15. We might need to do a full-blown rework which will be marked with a proper major version upgrade.

packages/nextjs-cache-handler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"next",
1919
"redis"
2020
],
21-
"version": "2.0.0-canary3",
21+
"version": "2.0.0-canary4",
2222
"type": "module",
2323
"license": "MIT",
2424
"description": "Next.js cache handlers",

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { REVALIDATED_TAGS_KEY } from "../constants";
22
import { isImplicitTag } from "../helpers/isImplicitTag";
33
import { CacheHandlerValue, Handler } from "./cache-handler.types";
4-
import { IncrementalCacheValue } from "next/dist/server/response-cache/types";
54
import {
6-
CreateRedisStringsHandlerOptions,
7-
ConvertedCachedRouteValue,
85
CachedRouteValue,
9-
ConvertedCachedAppPageValue,
10-
CachedAppPageValue,
6+
IncrementalCachedAppPageValue,
7+
IncrementalCacheValue,
8+
} from "next/dist/server/response-cache/types";
9+
import {
10+
CreateRedisStringsHandlerOptions,
11+
RedisCompliantCachedAppPageValue,
12+
RedisCompliantCachedRouteValue,
1113
} from "./redis-strings.types";
1214

1315
/**
@@ -327,7 +329,7 @@ export default function createHandler({
327329
const kind = value?.kind;
328330

329331
if (kind === "APP_ROUTE") {
330-
const appRouteData = value as unknown as ConvertedCachedRouteValue;
332+
const appRouteData = value as unknown as RedisCompliantCachedRouteValue;
331333
const appRouteValue = value as unknown as CachedRouteValue;
332334

333335
if (appRouteValue?.body) {
@@ -336,8 +338,8 @@ export default function createHandler({
336338
appRouteData.body = appRouteValue.body.toString();
337339
}
338340
} else if (kind === "APP_PAGE") {
339-
const appPageData = value as unknown as ConvertedCachedAppPageValue;
340-
const appPageValue = value as unknown as CachedAppPageValue;
341+
const appPageData = value as unknown as RedisCompliantCachedAppPageValue;
342+
const appPageValue = value as unknown as IncrementalCachedAppPageValue;
341343

342344
if (appPageValue?.rscData) {
343345
// Convert rscData Buffer to string
@@ -363,7 +365,7 @@ export default function createHandler({
363365
const kind = value?.kind;
364366

365367
if (kind === "APP_ROUTE") {
366-
const appRouteData = value as unknown as ConvertedCachedRouteValue;
368+
const appRouteData = value as unknown as RedisCompliantCachedRouteValue;
367369

368370
if (appRouteData?.body) {
369371
// Convert body string to Buffer
@@ -372,8 +374,8 @@ export default function createHandler({
372374
appRouteValue.body = Buffer.from(appRouteData.body, "utf-8");
373375
}
374376
} else if (kind === "APP_PAGE") {
375-
const appPageData = value as unknown as ConvertedCachedAppPageValue;
376-
const appPageValue = value as unknown as CachedAppPageValue;
377+
const appPageData = value as unknown as RedisCompliantCachedAppPageValue;
378+
const appPageValue = value as unknown as IncrementalCachedAppPageValue;
377379

378380
if (appPageData.rscData) {
379381
// Convert rscData string to Buffer

packages/nextjs-cache-handler/src/handlers/redis-strings.types.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
import type { createClient } from "@redis/client";
22

3-
export type CachedRouteValue = {
4-
kind: "APP_ROUTE";
5-
body: Buffer | undefined;
6-
};
7-
8-
export type ConvertedCachedRouteValue = {
3+
export type RedisCompliantCachedRouteValue = {
94
// See: https://github.com/vercel/next.js/blob/f5444a16ec2ef7b82d30048890b613aa3865c1f1/packages/next/src/server/response-cache/types.ts#L97
10-
kind: "ROUTE";
5+
kind: "APP_ROUTE";
116
body: string | undefined;
127
};
138

14-
export type CachedAppPageValue = {
15-
kind: "APP_PAGE";
16-
rscData: Buffer | undefined;
17-
segmentData: Map<string, Buffer> | undefined;
18-
};
19-
20-
export type ConvertedCachedAppPageValue = {
9+
export type RedisCompliantCachedAppPageValue = {
2110
// See: https://github.com/vercel/next.js/blob/f5444a16ec2ef7b82d30048890b613aa3865c1f1/packages/next/src/server/response-cache/types.ts#L76
22-
kind: "PAGE";
11+
kind: "APP_PAGE";
2312
rscData: string | undefined;
2413
segmentData: Record<string, string> | undefined;
2514
};

0 commit comments

Comments
 (0)