This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the workflows category.
Last Updated: 2024-11-23
When copying code from one codebase (React Native) to another (React Web), scan for any constants.
I copied this code over from Project S backend to Project S frontend:
export function switchLocale(locale = "de") {
i18n.locale = locale;
i18n.fallbacks = true;
}
const autoDetectedLocale = Localization.locale;
switchLocale(autoDetectedLocale);
export function translate(key) {
return i18n.t(key);
}
export default translate;
Having just tested it in the original context of the other codebase, I assumed it would work in the new codebase, so I committed and left the office.
Too soon, alas. This code caused a failure on a team-mate's machine.
What caused this? Proximately, it was because I didn't test the changes on the second new codebase. Just because I tested it in one context (the old codebase), does not mean it will work in another - i.e. code that is copied verbatim from another codebase should be assumed to be broken.
More directly, the issue was because this code referenced the Localization
constant which was available within React Native but not React web.