fix: server edit view components don't receive document id prop (#13526)
### What? Make the document `id` available to server-rendered admin components that expect it—specifically `EditMenuItems` and `BeforeDocumentControls`—so `props.id` matches the official docs. ### Why? The docs show examples using `props.id`, but the runtime `serverProps` and TS types didn’t include it. This led to `undefined` at render time. ### How? - Add id to ServerProps and set it in renderDocumentSlots from req.routeParams.id. Fixes #13420
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { CollectionConfig } from 'payload'
|
||||
|
||||
import { editMenuItemsSlug, postsCollectionSlug, uploadCollectionSlug } from '../slugs.js'
|
||||
import { editMenuItemsSlug } from '../slugs.js'
|
||||
|
||||
export const EditMenuItems: CollectionConfig = {
|
||||
slug: editMenuItemsSlug,
|
||||
@@ -11,6 +11,9 @@ export const EditMenuItems: CollectionConfig = {
|
||||
{
|
||||
path: '/components/EditMenuItems/index.js#EditMenuItems',
|
||||
},
|
||||
{
|
||||
path: '/components/EditMenuItemsServer/index.js#EditMenuItemsServer',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
13
test/admin/components/EditMenuItemsServer/index.tsx
Normal file
13
test/admin/components/EditMenuItemsServer/index.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { EditMenuItemsServerProps } from 'payload'
|
||||
|
||||
import React from 'react'
|
||||
|
||||
export const EditMenuItemsServer = (props: EditMenuItemsServerProps) => {
|
||||
const href = `/custom-action?id=${props.id}`
|
||||
|
||||
return (
|
||||
<div>
|
||||
<a href={href}>Custom Edit Menu Item (Server)</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -731,7 +731,7 @@ describe('Document View', () => {
|
||||
})
|
||||
|
||||
describe('custom editMenuItem components', () => {
|
||||
test('should render custom editMenuItems component', async () => {
|
||||
test('should render custom editMenuItems client component', async () => {
|
||||
await page.goto(editMenuItemsURL.create)
|
||||
await page.locator('#field-title')?.fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
@@ -746,6 +746,51 @@ describe('Document View', () => {
|
||||
|
||||
await expect(customEditMenuItem).toBeVisible()
|
||||
})
|
||||
|
||||
test('should render custom editMenuItems server component', async () => {
|
||||
await page.goto(editMenuItemsURL.create)
|
||||
await page.locator('#field-title')?.fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
|
||||
const threeDotMenu = page.getByRole('main').locator('.doc-controls__popup')
|
||||
await expect(threeDotMenu).toBeVisible()
|
||||
await threeDotMenu.click()
|
||||
|
||||
const popup = page.locator('.popup--active .popup__content')
|
||||
await expect(popup).toBeVisible()
|
||||
|
||||
const customEditMenuItem = popup.getByRole('link', {
|
||||
name: 'Custom Edit Menu Item (Server)',
|
||||
})
|
||||
|
||||
await expect(customEditMenuItem).toBeVisible()
|
||||
})
|
||||
|
||||
test('should render doc id in href of custom editMenuItems server component link', async () => {
|
||||
await page.goto(editMenuItemsURL.create)
|
||||
await page.locator('#field-title')?.fill(title)
|
||||
await saveDocAndAssert(page)
|
||||
|
||||
const threeDotMenu = page.getByRole('main').locator('.doc-controls__popup')
|
||||
await expect(threeDotMenu).toBeVisible()
|
||||
await threeDotMenu.click()
|
||||
|
||||
const popup = page.locator('.popup--active .popup__content')
|
||||
await expect(popup).toBeVisible()
|
||||
|
||||
const customEditMenuItem = popup.getByRole('link', {
|
||||
name: 'Custom Edit Menu Item (Server)',
|
||||
})
|
||||
|
||||
await expect(customEditMenuItem).toBeVisible()
|
||||
|
||||
// Extract the document id from the edit page URL (last path segment)
|
||||
const editPath = new URL(page.url()).pathname
|
||||
const docId = editPath.split('/').filter(Boolean).pop()!
|
||||
|
||||
// Assert the href contains the same id
|
||||
await expect(customEditMenuItem).toHaveAttribute('href', `/custom-action?id=${docId}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user