Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,5 +786,6 @@
"785": "Request body exceeded %s",
"786": "Server Actions are not enabled for this application. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
"787": "Failed to find Server Action. This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
"788": "Failed to find Server Action%s. This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action"
"788": "Failed to find Server Action%s. This request might be from an older or newer deployment.\\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
"789": "LRUCache: calculateSize returned %s, but size must be > 0. Items with size 0 would never be evicted, causing unbounded cache growth."
}
3 changes: 2 additions & 1 deletion packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export default class DevServer extends Server {
// 5MB
5 * 1024 * 1024,
function length(value) {
return JSON.stringify(value.staticPaths)?.length ?? 0
// Ensure minimum size of 1 for LRU eviction to work correctly
return JSON.stringify(value.staticPaths)?.length || 1
}
)
this.renderOpts.ampSkipValidation =
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/server/lib/lru-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ export class LRUCache<T> {
*/
public set(key: string, value: T): void {
const size = this.calculateSize?.(value) ?? 1
if (size <= 0) {
throw new Error(
`LRUCache: calculateSize returned ${size}, but size must be > 0. ` +
`Items with size 0 would never be evicted, causing unbounded cache growth.`
)
}
if (size > this.maxSize) {
console.warn('Single item size exceeds maxSize')
return
Expand Down
5 changes: 4 additions & 1 deletion packages/next/src/server/lib/router-utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export async function setupFsCheck(opts: {
}) {
const getItemsLru = !opts.dev
? new LRUCache<FsOutput | null>(1024 * 1024, function length(value) {
if (!value) return 0
if (!value) {
// Null entries (negative cache) still need a non-zero size for LRU eviction
return 1
}
return (
(value.fsPath || '').length +
value.itemPath.length +
Expand Down
Loading