Can you please what steps for that. And somehow I prevent for that. Because when you say flashing I know flashing the rom. But flash the persist partition I don't get it. I'm sorry. Can you explain more how can I prevent that. I'm thinking to use Los recovery rather than twrp . For safety
You might end up in problems with persist if you try to wipe persist or try to flash a .img file to the persist partition.
Yes, you can be a little bit safer by using LineageOS recovery.
If you wish, you can backup persist by running this on your computer while the phone is connected to a PC, ADB is enabled on the phone and the phone is in recovery (Command may not work on LineageOS recovery, if doesn't, try it out at system with Magisk or try a different recovery)
adb shell dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/persist.img
but don't flash the persist.img just yet, try out other fixes before actually touching your persist.