there are several different solutions being suggested online and I haven't found a single one that allows me to restart both precesses successfully (compositing gets disabled, complains about no display not being found, plasma gets terminated but wont restart, or plasma gets terminated but the applets start to work in really weird ways) I find myself frequently needing to use this feature due to desktop freezing, either because of third-party software, ram consumption or KDE bugs (hard to figure out). I don't want to log out or reboot cause then I lose all my work. Due to it's single-threaded design, Gnome (on X) has a one liner: --replace KDE needs some kind of script but I can't figure out what that script should be. I suspect many users are in the same position (as evidenced by the popularity of this question and the variety of answers). It is also unclear whether the solution for X and Wayland would be different. People need a simple, reliable way too unbork the shell and WM in case of emergency. It's a wishlist, but I'd like it have a high priority.
example: https://www.reddit.com/r/kde/comments/a5d2ly/how_do_you_properly_restart_kwin_and_plasmashell/
You shouldn't find yourself in the situation where you would need to do this. File bug reports for the individual issues but just restarting everything all the time is not a solution and not something we encourage. There's ways to do this: kwin_x11 --replace for KWin and plasmashell --replace for plasmashell.