port over #13746 & 1f329f8f17aa989eabc6e94bdcab93e69ef0e463