You’ll bake your shingles if they are asphalt. This voids any warranties if you don’t allow them ventilation underneath. As long as you have that or another shingle/roof type, you’ll be fine. You need to make sure that you have good enough ventilation as it will be extremely air tight so you’ll need some sort of mechanical ventilations or air conditioning. Moisture control will be key as well. Take your time because certain foams will off gas and will cause headaches if you close them up too quick.
A company I worked for did spray foam in modular housing and you just need to be aware of some of those issues. Just need to have a plan to reduce moisture, increase ventilation, and not impact your health with spray foam.