Merged: Avoid scanning detached nodes

(The selection API does not work on them.)
comment