Files
payloadcms/test/live-preview/config.ts
Jacob Fletcher ca3f054041 fix(next): force inactive live preview after passing conditions (#14048)
Follow-up to #14012.

Once live preview conditions have passed, it is jarring for the live
preview window to suddenly appear. It should be that, despite
preferences, if the live preview window did not _load_ active, then it
should not become active until the user explicitly toggles it on.

This is especially poor UX while creating a new doc. If the conditional
URL is based on a field that has't been filled yet, upon filling that
field (with autosave), live preview suddenly appears and the entire page
shifts mid-edit.

Before:


https://github.com/user-attachments/assets/0da75306-eed3-4a77-bc58-d8a8dd0254bf

After:


https://github.com/user-attachments/assets/c7918601-959d-4ac5-b168-066afc3d879d

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1211534009142634
2025-10-03 17:09:02 +01:00

80 lines
2.4 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { MediaBlock } from './blocks/MediaBlock/index.js'
import { Categories } from './collections/Categories.js'
import { CollectionLevelConfig } from './collections/CollectionLevelConfig.js'
import { ConditionalURL } from './collections/ConditionalURL.js'
import { CustomLivePreview } from './collections/CustomLivePreview.js'
import { Media } from './collections/Media.js'
import { Pages } from './collections/Pages.js'
import { Posts } from './collections/Posts.js'
import { SSR } from './collections/SSR.js'
import { SSRAutosave } from './collections/SSRAutosave.js'
import { StaticURLCollection } from './collections/StaticURL.js'
import { Tenants } from './collections/Tenants.js'
import { Users } from './collections/Users.js'
import { Footer } from './globals/Footer.js'
import { Header } from './globals/Header.js'
import { seed } from './seed/index.js'
import {
customLivePreviewSlug,
desktopBreakpoint,
mobileBreakpoint,
pagesSlug,
postsSlug,
ssrAutosavePagesSlug,
ssrPagesSlug,
} from './shared.js'
import { formatLivePreviewURL } from './utilities/formatLivePreviewURL.js'
export default buildConfigWithDefaults({
localization: {
defaultLocale: 'en',
locales: ['en', 'es'],
},
admin: {
importMap: {
baseDir: path.resolve(dirname),
},
livePreview: {
// You can define any of these properties on a per collection or global basis
// The Live Preview config cascades from the top down, properties are inherited from here
url: formatLivePreviewURL,
breakpoints: [mobileBreakpoint, desktopBreakpoint],
collections: [
pagesSlug,
postsSlug,
ssrPagesSlug,
ssrAutosavePagesSlug,
customLivePreviewSlug,
],
globals: ['header', 'footer'],
},
},
cors: ['http://localhost:3000', 'http://localhost:3001'],
csrf: ['http://localhost:3000', 'http://localhost:3001'],
collections: [
Users,
Pages,
Posts,
SSR,
SSRAutosave,
Tenants,
Categories,
Media,
CollectionLevelConfig,
StaticURLCollection,
CustomLivePreview,
ConditionalURL,
],
globals: [Header, Footer],
onInit: seed,
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
blocks: [MediaBlock],
})