Should take care of resources duplication/reordering when a custom root_id is defined.

See #11343
Take care of resources duplication/reordering when a custom root_id is defined.

* origin/pr/11344:
  Should take care of resources duplication/reordering when a custom root_id is defined.