It would depend on why it was invalid.
If the penitent purposely omitted a mortal sin, the confession was invalid. If they then later properly confessed but had legitimately forgotten about the invalid confession, they were validly absolved. However, they must mention the invalid confession at their next confession.
Now if one had only venial sins, and the confession was invalid due to defect of form (priest forgot to say absolution, for example), there would be no need to mention those sins at a subsequent confession since venial sins need not be mentioned in confession. However, confessing venial sins is edifying so one should re-confess them in my opinion (though it is not required).
Now if there were a mortal sin confessed at the invalid confession (presuming invalid due to defect of form), those were validly absolved at the valid confession. However, they must be mentioned at the next confession because they were not mentioned, and need to mentioned when they are remembered.
So it really depends on the circumstances to a certain point…