I think it happens in France sometimes, and it’s one of the roles of the Constitutional Council to strike unrelated measures from laws.
That doesn't prevent it from happening all the time, of course. The Conseil Constitutionnel sometimes strikes the "riders" if the law being voted is referred to the Council -- but referral isn't mandatory.
https://www.conseil-constitutionnel.fr/publications/titre-vi... [in French]
https://www.parliament.uk/site-information/glossary/long-tit...