payload icon indicating copy to clipboard operation
payload copied to clipboard

[Payload 3.0.1] Custom Server Components Not Receiving Any Properties

Open danhstevens opened this issue 1 year ago • 5 comments

Describe the Bug

According to the documentation (https://payloadcms.com/docs/admin/components#default-props), custom server components are provided with properties such as the payload class. However, no properties are passed into server components.

Example component:

import React from 'react'

export const TeamSelector = async ({ payload }) => {
  console.log('SHOULD HAVE A PAYLOAD OBJECT HERE', payload) // undefined
  return <div>123</div>
}

Expected Result: SHOULD HAVE A PAYLOAD OBJECT HERE [payload class data] Actual Result: SHOULD HAVE A PAYLOAD OBJECT HERE undefined

Link to the code that reproduces this issue

https://github.com/danhstevens/payload-issue

Reproduction Steps

  1. Create a new Payload project (v3)
  2. Add a custom server component that accepts any properties and apply to payload.config.ts
  3. Note how no properties are passed into the component

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Payload: 3.0.1
Node: 20

danhstevens avatar Nov 19 '24 20:11 danhstevens

Just noting that this has to do with the actions property specifically.

JarrodMFlesch avatar Nov 20 '24 19:11 JarrodMFlesch

Also affects client components. Using the basic template from the docs here This is all I have for config:

    components: {
      views: {
        dashboard: {
          Component: '@/components/payload/views/Root'
        }
      }
    }

SelfhostedPro avatar Nov 21 '24 19:11 SelfhostedPro

Still an issue in 3.2.2. Can't believe they keep shipping new versions without fixing a so evident problem.

mattiaz9 avatar Dec 01 '24 08:12 mattiaz9

Also affects client components. Using the basic template from the docs here This is all I have for config:

    components: {
      views: {
        dashboard: {
          Component: '@/components/payload/views/Root'
        }
      }
    }

You are trying to access server props in a client component. The props are different for client and server components. Remove use client from that file and you will be able to access the server properties.

If you need to use a client component in this case (which I doubt since I don't see any state), then you could compose it better and thread client safe props down to your client component.

JarrodMFlesch avatar Dec 16 '24 13:12 JarrodMFlesch

I tried a client component after it wasn’t working without ‘use client’ good to know that’s normal behavior though.

SelfhostedPro avatar Dec 16 '24 18:12 SelfhostedPro

I believe @akhrarovsaid fixed this in this PR!

JarrodMFlesch avatar Jan 06 '25 20:01 JarrodMFlesch

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Jan 08 '25 04:01 github-actions[bot]