This reverts commit 2765660101, which reverted a commit 0c7dce77dd, so we're reintroducing the same code from that commit here.
2765660101
0c7dce77dd