Skip to content

Commit bfb2e4c

Browse files
committed
ref(nitro, nuxt): inline == null checks for nullish detection
Replaces the two duplicated `isEmptyValue` helpers with inline `x == null` checks, matching the idiom already used across the codebase, rather than adding a shared helper to core.
1 parent 48b1434 commit bfb2e4c

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

packages/nitro/src/runtime/hooks/captureStorageEvents.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ function normalizeMethodName(methodName: string): string {
9999
return methodName.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
100100
}
101101

102-
function isEmptyValue(value: unknown): value is null | undefined {
103-
return value === null || value === undefined;
104-
}
105-
106102
interface CacheEntry<T = unknown> {
107103
value?: T;
108104
expires?: number;
@@ -116,7 +112,7 @@ interface ResponseCacheEntry {
116112

117113
function isCacheHit(key: unknown, value: unknown): boolean {
118114
try {
119-
const isEmpty = isEmptyValue(value);
115+
const isEmpty = value == null;
120116
if (isEmpty || typeof key !== 'string' || !CACHED_FN_HANDLERS_RE.test(key)) {
121117
return !isEmpty;
122118
}
@@ -133,7 +129,7 @@ function validateCacheEntry(
133129
key: string,
134130
entry: CacheEntry | CacheEntry<ResponseCacheEntry & { status: number }>,
135131
): boolean {
136-
if (isEmptyValue(entry.value)) {
132+
if (entry.value == null) {
137133
return false;
138134
}
139135

packages/nuxt/src/runtime/utils/instrumentStorage.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ function normalizeMethodName(methodName: string): string {
209209
return methodName.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
210210
}
211211

212-
/**
213-
* Checks if the value is empty, used for cache hit detection.
214-
*/
215-
function isEmptyValue(value: unknown): value is null | undefined {
216-
return value === null || value === undefined;
217-
}
218-
219212
/**
220213
* Creates the span start options for the storage method.
221214
*/
@@ -267,7 +260,7 @@ function normalizeKey(key: unknown, prefix: string): string {
267260
return `${prefix}${key.key}`;
268261
}
269262

270-
return `${prefix}${isEmptyValue(key) ? '' : String(key)}`;
263+
return `${prefix}${key == null ? '' : String(key)}`;
271264
}
272265

273266
const CACHED_FN_HANDLERS_RE = /^nitro:(functions|handlers):/i;
@@ -280,7 +273,7 @@ const CACHED_FN_HANDLERS_RE = /^nitro:(functions|handlers):/i;
280273
*/
281274
function isCacheHit(key: unknown, value: unknown): boolean {
282275
try {
283-
const isEmpty = isEmptyValue(value);
276+
const isEmpty = value == null;
284277
// Empty value means no cache hit either way
285278
// Or if key doesn't match the cached function or handler patterns, we can return the empty value check
286279
if (isEmpty || typeof key !== 'string' || !CACHED_FN_HANDLERS_RE.test(key)) {
@@ -301,7 +294,7 @@ function validateCacheEntry(
301294
key: string,
302295
entry: CacheEntry | CacheEntry<ResponseCacheEntry & { status: number }>,
303296
): boolean {
304-
if (isEmptyValue(entry.value)) {
297+
if (entry.value == null) {
305298
return false;
306299
}
307300

0 commit comments

Comments
 (0)