Skip to content

Commit

Permalink
Allow for skipping visibility in preview element (fix flickering issu…
Browse files Browse the repository at this point in the history
…e) (#4408)

* temp: DROP AFTER APPROVAL, sets up case

* chore(core): change naming on visibility in PreviewLoader

* chore(core): add __internal_skip_visibility_check prop to previewLoader

* chore(core): rename isPTE to match name

* style(core): rename prop

* fix(core): remove skipVisibility based layout in PreviewLoader & add condition within PTE
  • Loading branch information
RitaDias committed Apr 25, 2023
1 parent 3f2b278 commit 05d813c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export const DefaultBlockObjectComponent = (props: BlockProps) => {
),
layout: isImagePreview ? 'blockImage' : 'block',
schemaType,
skipVisibilityCheck: true,
value,
})}
</Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export const DefaultInlineObjectComponent = (props: BlockProps) => {
{renderPreview({
layout: 'inline',
schemaType,
skipVisibilityCheck: true,
value,
fallbackTitle: 'Click to edit',
})}
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/form/types/renderCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface RenderPreviewCallbackProps<TLayoutKey = PreviewLayoutKey> {
withRadius?: boolean
withShadow?: boolean
schemaType: SchemaType
skipVisibilityCheck?: boolean
style?: CSSProperties
}

Expand Down
18 changes: 12 additions & 6 deletions packages/sanity/src/core/preview/components/PreviewLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@ export function PreviewLoader(
component: ComponentType<Omit<PreviewProps, 'renderDefault'>>
}
): ReactElement {
const {layout, value, component, style: styleProp, schemaType, ...restProps} = props
const {
layout,
value,
component,
style: styleProp,
schemaType,
skipVisibilityCheck,
...restProps
} = props

const [element, setElement] = useState<HTMLDivElement | null>(null)
const isPTE = layout && ['inline', 'block', 'blockImage'].includes(layout)

// Subscribe to visibility
const visibility = useVisibility({
// NOTE: disable when PTE preview
element: isPTE ? null : element,
const isVisible = useVisibility({
element: skipVisibilityCheck ? null : element,
hideDelay: _HIDE_DELAY,
})

// Subscribe document preview value
const preview = useValuePreview({
enabled: isPTE || visibility,
enabled: skipVisibilityCheck || isVisible,
schemaType,
value,
})
Expand Down

2 comments on commit 05d813c

@vercel
Copy link

@vercel vercel bot commented on 05d813c Apr 25, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 05d813c Apr 25, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.