I've read stuff that a big solar flare could take out the whole electric grid and that it would take so long to restore it with parts we don't even have that things would basically devolve into chaos.
It could, but it is quite unlikely to happen. More plausible is a NEMP, in which an adversarial foreign state uses a nuclear explosion in the upper layers of the atmosphere to create a similar effect. A good fiction book in this regard is "One Second After" by William R. Forstchen.
All governments of note have taken some precautionary measures; hardening critical machinery/infrastructure, but you can't plausibly do that for every bit of hardware in your country. Imagine the effect of seeing most cars dead on the street because the EMP took them out. Imagine not being able to call home, or having refrigerated foods.
https://emptaskforce.us/wp-content/uploads/2023/01/A-Call-to...