Like what we’re doing? Star us on GitHub!

Why does the afterRead hook run multiple times for just one page load?

Alessio 🍣
last month
3

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/6ba997cb994d4a32bbe29d0f75bb87b9

First 5 times siblingdata works as usual. Last 10 times siblingdata is empty.

  • jesschow
    Payload Team
    2 weeks ago

    Hey @Alessio 🍣 , I just tried this out and got 6 times... which seems a lot, all of them had siblingData however

  • Alessio 🍣
    2 weeks ago

    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

  • jesschow
    Payload Team
    2 weeks ago

    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

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More