Retirement tax questions

Regarding your second paragraph, if that's true then what about my Roth contributions to the same 401k account? Or after-tax contributions for the "mega-backdoor" strategy? I know that those can be rolled into a Roth IRA without paying any taxes. It feels like they would need to keep track of the different proportions within the same account or else these common popular strategies wouldn't be possible. So given that, what is it about loan repayments that causes it to get a different treatment than other after-tax amounts, if that is the case?