The way spray foam is applied leads to it encapsulating the rafter timber on three sides, so any moisture from the upper surface, broken felt, nail holes etc is trapped in the timber and does not freely evaporate - leading to mould and timber rot.
Rigid insulation board between timber is not so...