Like so many other things in D & D 5th, this is left to the call of "the agent on the ground" rather than the "seat" – that is to say that it is the DM who can actually see the situation and make the best judgment call and decision. The basic rules of the spell are simple enough to work in most situations, but do not attempt the sisyphean task of specifying beforehand the operation of each possible case.
Is a cotton shirt a barrier? Is a soap bubble? Is it a wooden box? Should there be temporal changes to the effect area? Some of these things go beyond the rules and explicitly make DM calls to be made. (Some of these things are do not – a cotton shirt, a linen curtain or a soap bubble can not be classified as "obstacles", as are creatures or walls, fireball or lightning. See PHB pages 196 and 204.)
This DM absolutely do not count soap bubbles, delicate curtains or cotton shirts in the area of effect. For the less obvious parts, I would also say that a wooden box could not fully contain it. But I have so many questions about the box before I can say what made happen. What is the size of the box? What is the thickness of the wood? Who did it and how well or grossly? What kind of wood is it? How the fireball even enter it? I would not use them in a formula, my mind – they would all have fueled my sense of the situation and color the exact nature of the events following the conflagration.
Similarly for this wall of wood on the way to the lightning – the default is that it stops the effect of the spell, but if there are extenuating circumstances, they are, well, mitigating. If this is clearly not a sustainable hurdle at the moment, then it would be necessary to think about the details of the case to make a decision about what exactly happens instead of the default case.
What is, for the better or for worse, how is written to work.
In general if, yes, the area of a spell is determined and set before the damage is applied. (This stems simply from a reading of the "zones of effect", PHB, page 204.) Usually, it's so obvious that it would seem odd to even need to assert it at the outset. The rare exceptions where is it do not obviously how that should work – as fireballs inside too small fireboxes – throw yourself into the DM, as an unforeseen / unpredictable exception.