Skip to content

Commit

Permalink
fix(sanity): allow "null" as valid cache/memo value for preview fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 26, 2024
1 parent 7aed0c0 commit 44f8fef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/sanity/src/core/preview/observeFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,
Expand Down

0 comments on commit 44f8fef

Please sign in to comment.