Prevent duplication in context root if new_document_in_root != true

Should fix #803 & #11310