Don't modify buffer in document visibility change handler if not connected