Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) said: My brother Fadl and I came riding on a donkey, and the Noble Prophet (peace and blessings be upon him) was leading the prayer at Mina or Arafat. I passed through the middle of the row, got down from the donkey, left it to graze, and joined the row. (In the narration of Bukhari: No one objected to me for this.)
Hadith Referenceسنن دارمي / من كتاب الصللاة / 1453
The chapter is that prayer is not invalidated by someone passing in front of the person praying, and Imam Darimi rahimahullah has mentioned the above hadith in which it is stated that a donkey and Sayyiduna Ibn Abbas radi Allahu anhu himself passed between the rows, but no one objected. The meaning derived from this is that prayer is not invalidated by a donkey passing in front.
However, to deduce from this hadith that prayer is not invalidated by anyone passing in front is not correct, because Sayyiduna Ibn Abbas radi Allahu anhu passed between the rows with his donkey, and the sutrah (barrier) of the imam is also considered the sutrah of the follower (muqtadi).
In the previous hadith, it is mentioned that prayer is invalidated by a donkey, a black dog, and a woman passing in front. Regarding this, Sahib al-Tuhfah Mubarakpuri rahimahullah has written, the summary of which is that when any of these three mentioned kinds pass in front of the person praying, there is a deficiency in the prayer because the heart of the person is affected by it. However, the prayer does not become absolutely nullified or invalid; this is the fatwa of the majority of the scholars, both early and later generations.