This mostly reverts the approach in #62628, which now the problem is better scoped, looks overengineered and instead focuses on the few cases where there's something to take care of. (cherry picked from commit a2ed82d3b2)
a2ed82d3b2