I'm rooted with Magisk 20.4 on miui 12 20.6.4, I did it like this :
-wipe data + cache/dalvik
-install rom
Then I tried to install magisk but error 1, so I flashed the rom's boot.img and I tried to install magisk again, and it worked
Recap :
-wipe data + cache/dalvik
-install rom
-try to...