Description
Describe the Bug
Currently the field React Hooks will provide FieldState
values for all fields in the document's config, except for those nested within Lexical Blocks. They are instead deeply nested within the richtext's own returned FieldState
.
Expected Behaviour
Fields defined using payload's field config should all be accessible via the React Hooks, regardless of whether they're defined in a Lexical Block feature or not. I would expect the schema paths for Lexical Blocks to exist as siblings to the richtext field, similar to arrays and standard blocks. Eg;
{
"arrayField": 1,
"arrayField.0.nestedField": "...",
"blocksField": 1,
"blocksField.0.nestedField": "...",
"richtextField": { },
"richtextField.0.nestedField": "..."
}
Link to the code that reproduces this issue
https://github.com/damnsamn/blank-payload-project/tree/issue/lexical-block-fields-react-hooks
Reproduction Steps
Context
Our TestCollection
consists of several text fields in various nested contexts:
fieldA
arrayField -> fieldB
blocksField-> fieldC
richTextField -> fieldD
fieldA
through fieldC
are directly accessible via their schema paths in the useAllFormFields
hook, but fieldD
isn'
Steps
- Create an item in Test Collection
- Fill out the form, adding at least one array item, block, and richtext block, each with their text values filled
- Check the devtools console for a log of the following input, which will log an object with all field values provided by
useAllFormFields()
:
const [allFields] = useAllFormFields()
const currentFieldValues = Object.fromEntries(
Object.entries(allFields).map(([key, field]) => [key, field.value]),
)
console.log(currentFieldValues)
- Note that there is no schema path for
fieldD
. Example output:
{
arrayField: 2,
arrayField.0.fieldB: "lalala",
arrayField.0.id: "67a052ab9e2fee1fb665ec8a",
arrayField.1.fieldB: "lalal",
arrayField.1.id: "67a052ad9e2fee1fb665ec8c",
blocksField: 1,
blocksField.0.blockName: undefined,
blocksField.0.blockType: "fieldCBlock",
blocksField.0.fieldC: "lalala",
blocksField.0.id: "67a052b19e2fee1fb665ec8e",
createdAt: undefined,
fieldA: "lalala",
listFields: undefined,
richTextField: {root: {…}},
updatedAt: undefined,
}
Which area(s) are affected? (Select all that apply)
area: core, area: ui
Environment Info
Binaries:
Node: 22.12.0
npm: 10.9.0
Yarn: N/A
pnpm: 10.0.0
Relevant Packages:
payload: 3.20.0
next: 15.1.5
@payloadcms/db-postgres: 3.20.0
@payloadcms/email-nodemailer: 3.20.0
@payloadcms/graphql: 3.20.0
@payloadcms/next/utilities: 3.20.0
@payloadcms/payload-cloud: 3.20.0
@payloadcms/richtext-lexical: 3.20.0
@payloadcms/translations: 3.20.0
@payloadcms/ui/shared: 3.20.0
react: 19.0.0
react-dom: 19.0.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:31 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6030
Available memory (MB): 18432
Available CPU cores: 12