Static variables in TypeScript overwritten on hot reload
bladeSk opened this issue · 1 comments
When using static class variables in TypeScript, the variables get overwritten on a hot reload. This breaks code where preserving the contents of static variables is important. In the repro case below, which is just a slightly modified demo project, it gets even weirder and the static variable does not change at all once hot-reloaded. 🤔
Reproducible Demo
https://github.com/bladeSk/rhl-ts-static-bug - the bug occurs in src/BuggyStaticCounter.tsx
I also tried private static globalCount?: number
instead of private static globalCount = 0
, but it has the same effect, the only difference being the variable initialized to undefined
instead of a 0
.
🤷♂️ Don't use ClassComponents, it's very hard to support them or don't use react-hot-loader - see the deprecation notice for this project. React-fast-refresh solves this problem from a bit different angle, but solves.