Skip to content

Commit c49268e

Browse files
committed
Fix fallback-true pages
1 parent 7135e65 commit c49268e

File tree

10 files changed

+184
-58
lines changed

10 files changed

+184
-58
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
},
4040
"[typescriptreact]": {
4141
"editor.defaultFormatter": "biomejs.biome"
42+
},
43+
"[html]": {
44+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4245
}
4346
}

apps/cache-testing/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"@neshca/cache-handler": "workspace:*",
2020
"axios": "1.8.3",
21-
"next": "15.2.2",
21+
"next": "15.2.3",
2222
"react": "19.0.0",
2323
"react-dom": "19.0.0",
2424
"redis": "4.7.0"
@@ -28,7 +28,7 @@
2828
"@repo/eslint-config": "workspace:*",
2929
"@repo/typescript-config": "workspace:*",
3030
"@types/node": "22.13.10",
31-
"@types/react": "19.0.10",
31+
"@types/react": "19.0.11",
3232
"@types/react-dom": "19.0.4",
3333
"dotenv-cli": "8.0.0",
3434
"eslint": "9.22.0",

apps/cache-testing/run-app-instances.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
import { scheduler } from 'node:timers/promises';
44
import Fastify from 'fastify';
5-
// biome-ignore lint/style/noNamespaceImport: pm2 works only with namespace import
6-
import * as pm2Default from 'pm2';
7-
8-
const { default: pm2 } = pm2Default as unknown as {
9-
default: typeof import('pm2');
10-
};
5+
import pm2 from 'pm2';
116

127
const args = process.argv
138
.slice(2)

apps/cache-testing/tests/pages.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { expect, test } from '@playwright/test';
33

44
const paths = [
55
'/pages/with-paths/fallback-blocking/200',
6-
// '/pages/with-paths/fallback-true/200',
6+
'/pages/with-paths/fallback-true/200',
77
'/pages/with-paths/fallback-false/200',
88
'/pages/no-paths/fallback-blocking/200',
9-
// '/pages/no-paths/fallback-true/200',
9+
'/pages/no-paths/fallback-true/200',
1010
// '/pages/no-paths/fallback-false/200', // this fails with native next.js cache
1111
];
1212

docs/cache-handler-docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"start:docs": "serve out"
1313
},
1414
"dependencies": {
15-
"next": "15.2.2",
15+
"next": "15.2.3",
1616
"nextra": "4.2.16",
1717
"nextra-theme-docs": "4.2.16",
1818
"react": "19.0.0",
@@ -22,7 +22,7 @@
2222
"@repo/eslint-config": "workspace:*",
2323
"@repo/typescript-config": "workspace:*",
2424
"@types/node": "22.13.10",
25-
"@types/react": "19.0.10",
25+
"@types/react": "19.0.11",
2626
"@types/react-dom": "19.0.4",
2727
"eslint": "9.22.0",
2828
"pagefind": "1.3.0",

internal/eslint-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"devDependencies": {
1010
"@eslint/js": "9.22.0",
11-
"@next/eslint-plugin-next": "15.2.2",
11+
"@next/eslint-plugin-next": "15.2.3",
1212
"eslint": "9.22.0",
1313
"eslint-config-prettier": "10.1.1",
1414
"eslint-plugin-react": "7.37.4",

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ export class CacheHandler implements NextCacheHandler {
386386

387387
static async #readPagesRouterPage(
388388
cacheKey: string,
389+
isFallback: boolean,
389390
): Promise<CacheHandlerValue | null> {
390391
let cacheHandlerValue: CacheHandlerValue | null = null;
391392
let pageHtmlHandle: fsPromises.FileHandle | null = null;
@@ -417,9 +418,11 @@ export class CacheHandler implements NextCacheHandler {
417418
const [pageHtmlFile, { mtimeMs }, pageData] = await Promise.all([
418419
pageHtmlHandle.readFile('utf-8'),
419420
pageHtmlHandle.stat(),
420-
fsPromises
421-
.readFile(pageDataPath, 'utf-8')
422-
.then((data) => JSON.parse(data) as object),
421+
isFallback
422+
? {}
423+
: fsPromises
424+
.readFile(pageDataPath, 'utf-8')
425+
.then((data) => JSON.parse(data) as object),
423426
]);
424427

425428
if (CacheHandler.#debug) {
@@ -849,14 +852,21 @@ export class CacheHandler implements NextCacheHandler {
849852
});
850853

851854
if (!cachedData && CacheHandler.#fallbackFalseRoutes.has(cacheKey)) {
852-
cachedData = await CacheHandler.#readPagesRouterPage(cacheKey);
855+
cachedData = await CacheHandler.#readPagesRouterPage(cacheKey, false);
853856

854857
// if we have a value from the file system, we should set it to the cache store
855858
if (cachedData) {
856859
await CacheHandler.#mergedHandler.set(cacheKey, cachedData);
857860
}
858861
}
859862

863+
if (ctx.isFallback) {
864+
cachedData = await CacheHandler.#readPagesRouterPage(
865+
cacheKey,
866+
ctx.isFallback,
867+
);
868+
}
869+
860870
return cachedData ?? null;
861871
}
862872

packages/cache-handler/src/use-cache/redis.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,6 @@ function createRedisCacheHandler(config: RedisConfig = {}) {
417417
errorRetryCount: 0,
418418
};
419419

420-
console.info(
421-
'entry.expire, entry.revalidate, entry.stale',
422-
entry.expire,
423-
entry.revalidate,
424-
entry.stale,
425-
);
426-
427420
// Store in Redis with an expiration
428421
await redisClient.set(
429422
getKey(cacheKey),

0 commit comments

Comments
 (0)