Is there documentation somewhere for the order in which hooks execute? Specifically between fields and collection hooks.
Example: I have a field called
slugwhich uses a
beforeValidatefield hook to format from the title (this is copied from the payload remix example). On that same collection I have a
beforeValidatecollection hook that generates a uriPath using that
slugfield.
Currently I think I'm hitting a race condition in the order those fire. I need the
slugto be formatted (the field hook) before generating the
uriPath. I know I could move the
formatSlugfield hook to the collection level but I'd rather understand what is happening.
Here is the source code for the update operation:
https://github.com/payloadcms/payload/blob/master/src/collections/operations/update.ts#L158-L187are you returning the slugified value from your field hook? You should be able to access that via
datain your collection beforeValidate function
If I'm reading all the correctly, Field hooks finish in no particular order but Collection hooks should wait for all the Field hooks to finish before running.
I'll need to figure out how to reproduce the issue I was seeing. Naturally it's not happening all the time (hence the wondering about a race condition)
That is correct, field validations run in parallel
you might find this discussion relevant
https://github.com/payloadcms/payload/discussions/2785(and an upcoming PR
https://github.com/payloadcms/payload/discussions/2889#discussioncomment-6730791)
Star
Discord
online
Get dedicated engineering support directly from the Payload team.