From 44f8fefee59eb2a04b8360fe3f091c80bb9c7896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 26 Sep 2024 12:36:42 +0200 Subject: [PATCH] fix(sanity): allow "null" as valid cache/memo value for preview fields --- packages/sanity/src/core/preview/observeFields.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/sanity/src/core/preview/observeFields.ts b/packages/sanity/src/core/preview/observeFields.ts index 91c99bcf816c..05f4fb9e2556 100644 --- a/packages/sanity/src/core/preview/observeFields.ts +++ b/packages/sanity/src/core/preview/observeFields.ts @@ -140,9 +140,10 @@ export function createObserveFields(options: { fields: FieldName[], apiConfig?: ApiConfig, ): CachedFieldObserver { - let latest: T | null = null + // Note: `undefined` means the memo has not been set, while `null` means the memo is explicitly set to null (e.g. we did fetch, but got null back) + let latest: T | undefined | null = undefined const changes$ = merge( - defer(() => (latest === null ? EMPTY : observableOf(latest))), + defer(() => (latest === undefined ? EMPTY : observableOf(latest))), (apiConfig ? (crossDatasetListenFields(id, fields, apiConfig) as any) : currentDatasetListenFields(id, fields)) as Observable,