Improved logic for keeping duplicates off container list

An alternative (and cheaper) solution to the problem in #1474. With this solution we don't rely on `nextContainer` having an initial value of undefined, so it is safe to reuse old nodes.