Skip to content

Conversation

jacobsfletch
Copy link
Member

Fixes #12286. Self managed fields, i.e. custom fields that define their own path as a prop, consume their parent's path instead of the path that was given to them.

This was introduced in #11973 where we began passing a new potentiallyStalePath arg to the useField hook that takes the path from context as priority. This change was necessary in order to fix stale paths during row manipulation while the server is processing.

This change, however, made it so that custom fields could no longer control their own path.

The fix is to lift the potentiallyStalePath logic out of Payload's default fields and pass it as a direct prop. This way the path prop is still available for direct use.

@jonathanelmgren
Copy link
Contributor

Hey @jacobsfletch can we get this going? This issue will also be fixed by this PR

@jacobsfletch
Copy link
Member Author

Closing in favor of #13806. It's possible I can pick back up on this in the future, but it may require some more substantial changes in architecture. @jonathanelmgren I left some notes in that PR on how to move forward for now.

jacobsfletch added a commit that referenced this pull request Sep 15, 2025
Fixes #12286. Supersedes
#12290.

As of
[v3.35.0](https://github.com/payloadcms/payload/releases/tag/v3.35.0),
you are no longer able to directly pass a `path` prop to a custom field
component.

For example:

```tsx
'use client'
import React from 'react'
import { TextField } from '@payloadcms/ui'
import type { TextFieldClientComponent } from 'payload'

export const MyCustomField: TextFieldClientComponent = (props) => {
  return (
    <TextField
      {...props}
      path="path.to.some.other.field" // This will not be respected, because this field's context takes precedence
    />
  )
}
```

This was introduced in #11973 where we began passing a new
`potentiallyStalePath` arg to the `useField` hook that takes the path
from context as priority. This change was necessary in order to fix
stale paths during row manipulation while the server is processing.

To ensure field components respect your custom path, you need to wrap
your components with their own `FieldPathContext`:

```tsx
'use client'
import React from 'react'
import { TextField, FieldPathContext } from '@payloadcms/ui'
import type { TextFieldClientComponent } from 'payload'

export const MyCustomField: TextFieldClientComponent = (props) => {
  return (
    <FieldPathContext path="path.to.some.other.field">
      <TextField {...props} />
    </FieldPathContext>
  )
}
```

It's possible we can remove this in the future. I explored this in
#12290, but it may require some more substantial changes in
architecture. These exports are labeled experimental to allow for any
potential changes in behavior that we may need to make in the future.

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210533177582945
@jonathanelmgren
Copy link
Contributor

@jacobsfletch Thx for context. I raised this PR as a targeted fix for #13764, since it seems consistent with the direction suggested in #13806 (explicitly enforcing field paths).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to use custom paths for payload UI components within custom component
2 participants