Hi,
I found your script for sxiv with ranger through the arch wiki. It is brilliant! However I've had issues with large folders (~3000 pictures) where sxiv shows fewer files. When you quit, it shows the next batch (then the next...). This seems to be the result of xarg limiting the length passed. Which I'm not sure is avoidable.
I'm a bit of a beginner at scripting, but I've got something working (shown below) and learned a bit by having a stab. I had to switch to a list on separate lines (not a problem as my files don't have line-breaks in them). As noted in your comments this probably isn't portable, but for me it works and is faster on large directories as I only have to call listfiles once.
I'm not confident enough to post this up (as I've probably broken lots of things through inexperience and it's all your work), so I wondered if you might make a note about when the other script fails (it took me ages to work out why) and maybe provide a simpler (if less portable) version.