Fixes #91995 by correctly calculating the layer's id for removal.