You are browsing as a guest. Sign up (or log in) to start making projects!

57m 19s logged

Flashback to when I said:

At the very least, I feel confident that this project is complete enough to be submitted now…

Yeah clearly that did NOT happen.

So I tried using my own app for its intended purpose on my own, and I ran into a crazy weird bug: sometimes when switching between the main page and connection page, it would duplicate the units that were selected.

What’s weirder is that it seemed to only affect the enemy units and not the your list…

It took me about 2 hours of debugging (unfortunately most of which was on Chrome DevTools debugger, so it didn’t count for stardance 😞) to finally find out the root cause.

The root cause was in how React.js handles refreshing data. So basically, whenever the data in my program changes (ie: the user hits next or start calculation on the connections page), it gets saved to the sessionStorage, after being processed into certain format. It saved the “your” unit lists then the “enemy” unit lists to the sessionStorage.

In the function that saves it to the sessionStorage, it has a local variable that is supposed to have the current data, which is normal. How it works is that the it sort of takes local variable and overrides the specific changes on top of it, then saves the whole thing to sessionStorage.

However, because it was using a React method to get the current data, it doesn’t immediately update itself, only updates when a new frame is drawn to the screen… So when the higher level code then tried to save the your unit list, the local variable was out of date, and applied the changes on top of an out of date data and then saved that to the sessionStorage.

This caused problems when switching between tabs since sessionStorage is the lifeline of the communication between them. I got around this problem by basically saving all of the data in one go instead of saving one part then the next part.

This was very frustrating to debug by myself but it feels rewarding now that I’ve done it. NOW I will submit this. My family is starting a roadtrip tomorrow morning so I won’t be able to code for a few days, I really want to get this off my plate before then.

Here’s my debugging setup I used for this:

0
1

Comments 0

No comments yet. Be the first!