Cherrypick f2fb841c into 3.2.x branch

See #6905 (closed). It needs some time in beta before hitting release, but I can't put it in 3.2.0 so it'll go in 3.2.1beta1.