Only trigger invalidate styles or layout if needed

To aid in performance, check if the CSS styles have changed before
touching the DOM element.