Skip to content

Commit 5f76eb2

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

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
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/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

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),

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"tasks": {
77
"build": {
88
"dependsOn": ["^build"],
9+
"cache": false,
910
"env": [
1011
"REDIS_URL",
1112
"REMOTE_CACHE_SERVER_BASE_URL",

0 commit comments

Comments
 (0)