Partially revert be398487ea4d6b8b53cb4e1174f051a74672ebd3.

Fixes bugs #21278 and #21291.