Skip to content

Commit 98e62b3

Browse files
authored
Handles pages router index route correctly (#125)
* Handles pages router index route correctly Ensures that the root route is correctly served by mapping it to the "/index" route, preventing issues with cache lookups and writes. * Version bump to 2.1.6
1 parent 7a6729c commit 98e62b3

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

packages/nextjs-cache-handler/package-lock.json

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

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.1.5",
21+
"version": "2.1.6",
2222
"type": "module",
2323
"license": "MIT",
2424
"description": "Next.js cache handlers",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ export class CacheHandler implements NextCacheHandler {
144144
static async #readPagesRouterPage(
145145
cacheKey: string,
146146
): Promise<CacheHandlerValue | null> {
147+
if (cacheKey === "/") {
148+
cacheKey = "/index";
149+
}
150+
147151
let cacheHandlerValue: CacheHandlerValue | null = null;
148152
let pageHtmlHandle: fsPromises.FileHandle | null = null;
149153

@@ -278,6 +282,10 @@ export class CacheHandler implements NextCacheHandler {
278282
cacheKey: string,
279283
pageData: IncrementalCachedPageValue,
280284
): Promise<void> {
285+
if (cacheKey === "/") {
286+
cacheKey = "/index";
287+
}
288+
281289
try {
282290
const pageHtmlPath = path.join(
283291
CacheHandler.#serverDistDir,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export async function registerInitialCache(
245245
) {
246246
const isAppRouter = router === "app";
247247

248-
if (isAppRouter && cachePath === "/") {
248+
if (cachePath === "/") {
249249
cachePath = "/index";
250250
}
251251

0 commit comments

Comments
 (0)