If you've found this post by the power of Google it means that you're doing cool things with Shopify Liquid, but you've hit an error. Let's talk quickly about the limit.
There is a limit of 20 unique handles with all_products on a page. As long as you're not pushing any more than 20 you'll never see the error.
The common place I see the Exceeded maximum number of unique handles for all_products error is on related product scripts where theme developers try and loop over every collection, and every product within that. Within those loops sits the all_products tag, getting called every single time. It's pretty easy to hit that 20 limit when you're using it 100s (if not 1000s of time on the one page).
There's no work around here so be sure to design your code around this limit.
If you can't optimise your code it's time to consider alternate - and perhaps better suited - options like collection, metafield, JavaScript, or combo of all.
What's the alternate JavaScript method?
Without going into the code the general idea would be to output the product handles somewhere in the DOM. This could be as data attributes on an element, or just as JavaScript global variables. You'd then run some additional JavaScript that would grab those handles and use the AJAX api to pull the product data from each of the items .json endpoints.
Drawbacks to this is that you won't have the content available until after page load but in almost every case this won't be a problem.
If you really need some code examples leave a comment and I'll hack something together.