[Magisk] zgfg:
When booting, Magisk initializes module by module

However, if there is a file named "disable" in the module's folder ("/data/adb/<module>"), then Magisk skips that module.

If you reboot, and if the file is still there, module will be skipped again (disabled), and so on.

To enable the module, you must remove the "disable" file

To the other side, if Magisk finds the file "remove", it will uninstall that module. It means not just deleting the module's folder, but before that, Magisk will execute the script uninstall.sh if such a script exists in the module's folder.

Therefore, when you need to uninstall a module, better do it properly (let Magisk execute its uninstall.sh script), than just by manually deleting the module's folder (through TWRP or root explorer)

When you tap to disable a module in Magisk app, app doesn't do anything else but it simply creating that file "disable" in the module's folder.

When you tap to enable, Magisk app simply removes the "disable" file.

Also, when you hit Uninstall a module, again Magisk app will simply create the "remove" file in the module's folder.

Next time you reboot, Magisk will find or not the files "remove" or "disable", and accordingly will remove or skip initiaizing that module

(Excersize: Disable a module through Magisk app. Then find and delete the file "disable" by root explorer. Reopen Magisk app and check if the module is still marked as disabled or not)

No magic here. And hence it doesn't matter do you manipulate those "remove" and "disable" files through Magisk app, through root explorer or through TWRP

However, if you have a bootloop, you cannot boot to the system (with Magisk) and therefore you cannot disable a particular module.

If you boot without Magisk, Magisk app (without root) cannot read /data/adb and therefore it cannot show if modules are installed or not.

Therefore, if you flash back the original img, Magisk app would have no control over the modules, and you couldn't use it to disable the modules

Hence, if you have a bootloop due to a Magisk module, you must somehow externally create those files "disable" or "remove"

When there is a TWRP - boot to TWRP, go to the module's folder and create the file "remove" or "disabe".

Next time you boot (but with Magisk, not with the stock img), module will be uninstalled or skipped (i.e., not enabled)

However, what could you do in case of bootloop but when TWRP is not available for your device?

That's why TJW introduced the trick with Safe mode:

When booting, Magisk can recognize if Android is booting to Safe or normal mode (that's why you must boot with Magisk to Safe mode, not without).

When Magisk recognizes the Android Safe mode, it will not just skip modules that time, but it will also create itself "disable" files for all modules - hence next times you boot (to normal mode), all modules will remain disabled as long as "disable" files remain there

Finally, there is (was) also the adb command:

adb wait-for-device shell magisk --remove-modules

But it was found that it doesn't work on all devices (some do not start adb server before initializing Magisk, hence adb cannot pass the command to uninstall the modules to Magisk).

That's why TJW later introduced the Safe mode trick (bcause of devices without TWRP and where the adb trick does not work)