How to fix swatches appearance in Magento 2.2.7 and 2.3.0?

Replace the line:
https://github.com/magento/magento2/blob/2.3.0/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml#L24-L24

with the following code block:
https://github.com/magento/magento2/blob/19e9ada1/app/code/Magento/Swatches/view/frontend/templates/product/listing/renderer.phtml#L24-L25

See also: How to fix broken images for swatches after upgrading Magento to 2.3.x?