New backport of fix to #21122
This reverts the previous backport from !7602 (merged) and cherry-picks the current state of !7625 (closed), which is now in the merge queue.
This reverts the previous backport from !7602 (merged) and cherry-picks the current state of !7625 (closed), which is now in the merge queue.