Obtaining root for the first time is different from retaining it. Mainly, disabling Magisk prior to the OTA update and the method for obtaining the boot image is different. Flashing the boot image and Magisk are identical.
These instructions are for retaining root access using Magisk.
If you do not already have root access, you need to follow the instructions for obtaining root access for the first time.
These first steps are all performed in your phone's settings menu.
Run the Magisk app and have it restore images by pressing the Uninstall button and choosing Restore Images.
Note: If you don't want a rooted phone anymore just reboot now.
If you forget to unlock your phone before you do the next steps you will have to reflash your boot image to stock, reboot your phone, turn of the lock screen and start over.
Tap Build number until developer options are enabled
Connect your phone to your computer with a USB cable and give your computer permission to do USB debugging with your phone.
You will need to capture the new boot image to re-install Magisk. This is much easier to do now that you already have root access on your device.
sudo adb shell
There are two boot partitions on this phone because it is an A/B phone and can contain two complete operating systems. This allows the phone to update while it is running and reboot into the second operating slot. If the new operating system does not work for some reason, the phone will fall back to the previous running image.
We need to know which slot is currently being used so we can pull the UPDATED image from the other slot. In the adb shell type:
Since this returns the CURRENT SLOT, the OTHER slot was updated and contains the boot image we want to save. If the current slot is A then you need to get the B image.
In the adb shell type:
On your phone you will be prompted to gain Super User access. Grant that permission.
To save by image use one of these commands depending on the boot image slot you require.
dd if=/dev/block/bootdevice/by-name/boot_a of=/sdcard/boota.img
dd if=/dev/block/bootdevice/by-name/boot_b of=/sdcard/bootb.img
I suggest you rename that .img file with the month date of the update (e.g. boot-may.img).
Restart the phone again and depress the volume down button while the phone restarts.
We need to install TWRP to this partition so we can re-install Magisk.
sudo fastboot flash boot twrp-mata_11.img
Now press the volume down button to select booting to recovery mode and press the power button to select. After a few moments TWRP will start.
Magisk may still be on your phone from when you first rooted.
You may have a different version of Magisk so instead of FILENAME use the name of the Magisk file you download:
sudo adb push FILENAME.zip /sdcard/
In TWRP press the INSTALL button.
Note: TWRP has a button to select if you want to flash an .img or a .zip file. You have to press "Install Image" to see the boot.img file and again later to see the Magisk file on the /sdcard partion of your phone.
Note: In TWRP you need to use the back button as well as the interface buttons for navigation.
Scroll down until you see the boot image you previously saved. Touch it and select the radio button labeled "Boot". Swipe to confirm flash. This actually overwrites TWRP with the boot image you extracted. At this point the phone is back to stock but we still have TWRP running.
When that has completed select and flash Magisk by pressing the Back button, the phone's back button, the Install Zip button, touch Magisk file, swipe to confirm flash.
There is no need to have TWRP installed as an app on your phone.
Settings - System - Developer options - USB debugging
It is safest to keep USB debugging disabled until you need it. Go to the developer options menu in settings and disable it.
You can also now set your lockscreen.
Settings - Security - Lockscreenback to the beginning