When you say 'switch', I assume you mean a transfer switch.
You must allow inverter to disconnect AC input and open its pass-through relay before switching to a different AC input with random AC phase difference from what inverter was running on for AC input.
If you immediately flip between shore AC and generator AC, or vice-versa, the pass-through relay will still be closed and generator will have a random phase relative to what shore power was which inverter is still in sync with.
Only when inverter's pass-through relay opens does inverter slowly skews back to internal inverter frequency/phase and then goes through a new relocking process when it sees a new AC input source before re-closing pass-through relay again on new AC source phase lock.
If you do not allow inverter's pass-through connect relay to release from AC input before applying a different AC input source, you might just pop AC input breaker, damage pass-through relay contacts, cause inverter to shut down with an error, or even damage inverter.