Avoiding that shock is generally (though not completely) resolved by going with a "target retirement"-style fund that shifts your portfolio towards less-risky assets the closer you get to depending on them. Barring this you can also approximate it yourself by weighting further into bonds and fixed-income assets as you age. The FIRE community does something similar with the "bond tent" strategy.
That said, I'm honestly deeply confused as to what you think the alternative is It's impossible to reliably predict crashes or their extent so by selling you're generally just locking in your losses. I personally know multiple people who liquidated during the Great Recession, and... well, not only did they sell at rock bottom prices during the fire sale, but they also failed to get back in to the market during the incredible rally of the last decade.
I know multiple people who got out during the Trump administration, expecting total financial meltdown. Those people are materially worse off than if they'd simply held. I know several who panic sold when the markets took a hit at the beginning of the pandemic. Yet again, they've locked in their losses and missed out on the positive returns that have occurred since then.
So, barring access to a crystal ball, what exactly do you think is the alternative?