Fix JS error when updating doc with remote changes