This MR ports to master the changes originally made in 21.9 through !51788 (merged).
/cc @aleopold @tadej @tstreble