Install Magisk in TWRP, with "Keep DM-Verity/AVB 2.0" option?
With Magisk 17.1 (introduced by topjohnwu in this commit), Magisk installer ZIP now detects system_root_image and keeps dm-verity/AVB 2.0 when being flashed in recovery. This should solve the issue most of the times (at least with my OnePlus 5 and OnePlus 6).

Alternatively, create a file at /data/.magisk with the following content:

KEEPFORCEENCRYPT=true
KEEPVERITY=true


This file will be parsed by the installer script (here) and the settings will be respected.