There is nothing Barrett could have done to avoid or mitigate what happened here. I have seen referees give YC for this, but I agree 100% agree with...
As I learnt it and understand it, the 10m offside line for non-participating players at a line-out lasts until the lineout is over - ball passed out...