I think this is the best possible example of why you should always develop websites using progressive enhancement. First, write the app without using any JavaScript. Test it. Make sure the core logic works as intended. Then add JavaScript to make it faster, pretties, simpler to use. That will most likely prevent fuckups such as this, and it will also result in better structured, easier to reason about architecture.