Backport of #9156