Imperative `isCrosswordCorrect()` function returns `false` after web page reloads
See original GitHub issueThanks for sharing this package!
I think I have run into a bug related to checking whether the crossword is correct.
When I fill in all the grid cells with correct letters and then call the imperative isCrosswordCorrect()
function, the function returns true
. That is what I expect it to do.
crosswordRef.current.isCrosswordCorrect(); // returns true ✅
However, when I then reload the web page (which leads to the grid being automatically re-populated with the same, correct letters) and then I call that same function again, the function returns false
, whereas I expect it to return true
since all the grid cells are still populated with correct letters.
crosswordRef.current.isCrosswordCorrect(); // returns false 😞
At this point, if I call the imperative reset()
function, fill in all the grid cells with the correct letters again, and then call the imperative isCrosswordCorrect()
function again, the latter function once again returns true
.
crosswordRef.current.reset();
crosswordRef.current.isCrosswordCorrect(); // returns true ✅
Here’s some information about the environment in which I observed this:
- OS: Windows 10
- Browser: Google Chrome Version 100.0.4896.88 (Official Build) (64-bit)
@jaredreisinger/react-crossword
version: 4.3.2- React version: 17.0.2
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
… and sure enough, digging into the guess-loading code, I see a comment I left for myself:
So, yeah… I need to “find correct answers”! 🤦
@gitname, thank you for the very-detailed repro case! I can look into this; my initial guess is that the “everything is correct” state is getting set during the “a letter has changed” processing, and isn’t getting set when loading the state from the browser’s local storage. 🤞🏼 it should be fairly easy to track down.
I think the non-page-reloading example is still causing the component to unmount and then remount, which would look exactly the same as a page reload as far as the component was aware. If that’s true, the same fix will take care of this scenario as well.