Empty matrix object after checking for a block type
So there are some changes to how .type() works in Craft 3 which you can read about here. What's happening is the type() you're setting here in your doNotCache is also getting applied later on in your template when you start actually looping over the blocks in entry.mainBody. There are two ways to solve this:


Reset the type() in your matrix block loop

{% for block in entry.mainBody.type(null).all() %}

Clone the mainBody field before you manipulate it

{% set doNotCache = clone(entry.mainBody).type('form').all()|length or craft.retour.getHttpStatus != 200 ? true : false %}