### What? Fix two live preview issues affecting client-side navigation: 1. Stale preview data leaking between pages using `useLivePreview`. 2. Erroneous fetches to `/api/undefined` and incorrect content rendering when preview events lack slugs. ### Why? The live-preview module cached merged preview data globally, which persisted across route changes, causing a new page to render with the previous page’s data. The client attempted to merge when preview events didn’t specify collectionSlug or globalSlug, producing an endpoint of undefined and triggering requests to /api/undefined, sometimes overwriting state with mismatched content. ### How? Clear the internal cache at the time of `subscribe()` so each page using `useLivePreview` starts from a clean slate. In `handleMessage`, only call `mergeData` when `collectionSlug` or `globalSlug` is present; otherwise return `initialData` and perform no request. Fixes #13792
51 lines
924 B
TypeScript
51 lines
924 B
TypeScript
import type { Header } from '../payload-types.js'
|
|
|
|
export const header: Partial<Header> = {
|
|
navItems: [
|
|
{
|
|
link: {
|
|
type: 'reference',
|
|
url: '',
|
|
reference: {
|
|
relationTo: 'pages',
|
|
value: '{{POSTS_PAGE_ID}}',
|
|
},
|
|
label: 'Posts',
|
|
},
|
|
},
|
|
{
|
|
link: {
|
|
type: 'reference',
|
|
url: '',
|
|
reference: {
|
|
relationTo: 'posts',
|
|
value: '{{POST_1_ID}}',
|
|
},
|
|
label: 'Post 1',
|
|
},
|
|
},
|
|
{
|
|
link: {
|
|
type: 'reference',
|
|
url: '',
|
|
reference: {
|
|
relationTo: 'posts',
|
|
value: '{{POST_2_ID}}',
|
|
},
|
|
label: 'Post 2',
|
|
},
|
|
},
|
|
{
|
|
link: {
|
|
type: 'reference',
|
|
url: '',
|
|
reference: {
|
|
relationTo: 'posts',
|
|
value: '{{POST_3_ID}}',
|
|
},
|
|
label: 'Post 3',
|
|
},
|
|
},
|
|
],
|
|
}
|