To determine the current WM in Wayland, neofetch first tries getting the process connected to the current Wayland display. If that fails, it checks all running processes against a hardcoded list of known WMs (which includes river).
In practice, it seems to prefer the value of XDG_CURRENT_DESKTOP, but idrk, neofetch is magic.
You might’ve seen people use fastfetch, which should just get it right, but is also magic, tho at least c and not bash.