Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(preview): remove full document preview support #7303

Merged
merged 1 commit into from
Aug 2, 2024
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
2 changes: 1 addition & 1 deletion packages/sanity/src/core/preview/createGlobalListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createGlobalListener(client: SanityClient) {
includeResult: false,
includePreviousRevision: false,
includeMutations: false,
visibility: 'transaction',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is setting it back to how it was before

visibility: 'query',
effectFormat: 'mendoza',
tag: 'preview.global',
},
Expand Down
23 changes: 1 addition & 22 deletions packages/sanity/src/core/preview/documentPreviewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
type WelcomeEvent,
} from '@sanity/client'
import {type PrepareViewOptions, type SanityDocument} from '@sanity/types'
import {pick} from 'lodash'
import {combineLatest, type Observable} from 'rxjs'
import {distinctUntilChanged, filter, map} from 'rxjs/operators'

Expand Down Expand Up @@ -108,16 +107,6 @@ export interface DocumentPreviewStoreOptions {
client: SanityClient
}

/** @internal
* Should the preview system fetch partial documents or full documents?
* Setting this to true will end up fetching full documents for everything that's currently being previewed in the studio
* This comes with an extra memory and initial transfer cost, but gives faster updating previews and less likelihood of displaying
* out-of-date previews as documents will be kept in sync by applying mendoza patches, instead of re-fetching preview queries
*
* TODO: Set to false before merging to main, see https://github.com/sanity-io/sanity/pull/7257/
* */
const PREVIEW_FETCH_FULL_DOCUMENTS = true

/** @internal */
export function createDocumentPreviewStore({
client,
Expand All @@ -135,17 +124,7 @@ export function createDocumentPreviewStore({
)

const observeDocument = createObserveDocument({client, mutationChannel: globalListener})

function getObserveFields() {
if (PREVIEW_FETCH_FULL_DOCUMENTS) {
return function observeFields(id: string, fields: string[], apiConfig?: ApiConfig) {
return observeDocument(id, apiConfig).pipe(map((doc) => (doc ? pick(doc, fields) : null)))
}
}
return createObserveFields({client: versionedClient, invalidationChannel})
}

const observeFields = getObserveFields()
const observeFields = createObserveFields({client: versionedClient, invalidationChannel})

const {observePaths} = createPathObserver({observeFields})

Expand Down
Loading