fix(next): prevent live preview url functions from firing unnecessarily (#13088)
Ensures Live Preview url functions aren't fired during create or on collections that do not have Live Preview enabled. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210743577153852
This commit is contained in:
@@ -329,14 +329,22 @@ export const renderDocument = async ({
|
||||
viewType,
|
||||
}
|
||||
|
||||
const isLivePreviewEnabled = Boolean(
|
||||
config.admin?.livePreview?.collections?.includes(collectionSlug) ||
|
||||
config.admin?.livePreview?.globals?.includes(globalSlug) ||
|
||||
collectionConfig?.admin?.livePreview ||
|
||||
globalConfig?.admin?.livePreview,
|
||||
)
|
||||
|
||||
const livePreviewConfig: LivePreviewConfig = {
|
||||
...(config.admin.livePreview || {}),
|
||||
...(isLivePreviewEnabled ? config.admin.livePreview : {}),
|
||||
...(collectionConfig?.admin?.livePreview || {}),
|
||||
...(globalConfig?.admin?.livePreview || {}),
|
||||
}
|
||||
|
||||
const livePreviewURL =
|
||||
typeof livePreviewConfig?.url === 'function'
|
||||
operation !== 'create'
|
||||
? typeof livePreviewConfig?.url === 'function'
|
||||
? await livePreviewConfig.url({
|
||||
collectionConfig,
|
||||
data: doc,
|
||||
@@ -350,6 +358,7 @@ export const renderDocument = async ({
|
||||
payload: initPageResult.req.payload,
|
||||
})
|
||||
: livePreviewConfig?.url
|
||||
: ''
|
||||
|
||||
return {
|
||||
data: doc,
|
||||
@@ -380,8 +389,8 @@ export const renderDocument = async ({
|
||||
>
|
||||
<LivePreviewProvider
|
||||
breakpoints={livePreviewConfig?.breakpoints}
|
||||
isLivePreviewEnabled={isLivePreviewEnabled && operation !== 'create'}
|
||||
isLivePreviewing={entityPreferences?.value?.editViewType === 'live-preview'}
|
||||
operation={operation}
|
||||
url={livePreviewURL}
|
||||
>
|
||||
{showHeader && !drawerSlug && (
|
||||
|
||||
@@ -21,8 +21,8 @@ export type LivePreviewProviderProps = {
|
||||
height: number
|
||||
width: number
|
||||
}
|
||||
isLivePreviewEnabled?: boolean
|
||||
isLivePreviewing: boolean
|
||||
operation?: 'create' | 'update'
|
||||
url: string
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ const getAbsoluteUrl = (url) => {
|
||||
export const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({
|
||||
breakpoints: incomingBreakpoints,
|
||||
children,
|
||||
isLivePreviewEnabled,
|
||||
isLivePreviewing: incomingIsLivePreviewing,
|
||||
operation,
|
||||
url: incomingUrl,
|
||||
}) => {
|
||||
const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')
|
||||
@@ -226,13 +226,6 @@ export const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({
|
||||
)
|
||||
}, [isLivePreviewing, setPreference, collectionSlug, globalSlug])
|
||||
|
||||
const isLivePreviewEnabled = Boolean(
|
||||
operation !== 'create' &&
|
||||
((collectionSlug && config?.admin?.livePreview?.collections?.includes(collectionSlug)) ||
|
||||
(globalSlug && config.admin?.livePreview?.globals?.includes(globalSlug)) ||
|
||||
entityConfig?.admin?.livePreview),
|
||||
)
|
||||
|
||||
return (
|
||||
<LivePreviewContext
|
||||
value={{
|
||||
|
||||
Reference in New Issue
Block a user