It's run a total of 15 (!!) times for just one page reload, even though I have attached that afterRead hook to just one single field. Is it supposed to work that way?
The collection I'm using:
https://paste.gg/p/anonymous/6ba997cb994d4a32bbe29d0f75bb87b9First 5 times siblingdata works as usual. Last 10 times siblingdata is empty.
Hey @alessiogr , I just tried this out and got 6 times... which seems a lot, all of them had siblingData however
hey hey, is there a reason why it runs multiple times? Or should it only run one time.
Will test it out later again - maybe it got better in a newer version of payload
Okay I've done a bit of learning from the team - if you are reloading the page in the admin UI it is not unexpected behavior, this is because there are many other variables that can cause it to run extra times including versions, preferences, access control, doc relationships etc.
If you hit the api route directly, you should see it only run once (which I found to be the case when I tested it).
If you get a chance to test again let me know what you find
@alessiogr I have a collection with multiple items. The collection config has a field with an afterRead hook
Is it normal that it fires for every item on the collection when viewing the items of the collection
/ Is there a way to make it only run when viewing a particular item
like not a specific item, but just when editing an item
Out of curiosity, what's your use case @notchr? 👀
With items, do you mean documents?
@alessiogr Yess
@tinouti We have a separate API that stores some user information
We want to call that API, pass an id stored on the payload user, and get back an array of some data
For each item in the array, we want to display a field
Interesting, definitely sounds like the perfect application for afterRead field hook 😅
Is there anything in
req
that might be different when on the edit page maybe, that you could use to condition the hook? 🤔
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.