MDL-41594 Bug fix for orphaned invisible categories

thanks to L.Sanocki