Question is pretty simple and arose when doing one of the usual integrals to find the electric field. This one concerned the field above the middle of a uniform line distribution of charge. If you wish to calculate the field you must take in mind that the horizontal components cancel. However if you just find the potential and then take the gradient you also get the correct field. How can the potential "know" that the horizontal parts cancel? It's quite amazing (too amazing for me) to be honest.