The annoying behavior you have described has been endemic to Macs for many years. It comes and goes with the seasons on different models, or maybe Mac OS X updates. Only God knows. My 2013 13” MacBook Air had been doing it occasionally during the winter, but with summer approaching I’ve not seen it lately.