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 2597041 commit 4fc46c4
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 @@ -154,9 +154,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 4fc46c4

Please sign in to comment.