Only trigger invalidate styles or layout if needed

Check if the CSS styles have changed before
touching the DOM element.