cds-snc / c19-benefits-node

Answer some questions to find which federal programs can help you https://covid-benefits.alpha.canada.ca/. - Répondez à quelques questions pour trouver quels programmes d’aide financière fédéraux s’offrent à vous https://covid-prestations.alpha.canada.ca/.
MIT License
2 stars 4 forks source link

Bug with French toggling not in prod #437

Open katewilhelm opened 4 years ago

katewilhelm commented 4 years ago

When I was testing a deployment for another PR, I found the re-emergence of a previously fixed bug. Something weird is happening with toggling to French and then going back to English and later it remembering the previous French request. Here's what I did:

  1. Get to results page in English.
  2. Toggle to French results.
  3. Use browser back button to go back to English results.
  4. Click start over

Here's what happened: Start page appears in French.

I tried this in prod and there was no problem.

katedee commented 4 years ago

For the record, I was able to reproduce this locally on master as well, so it seems to not be specific to my PR. Will keep looking into it though, just wanted to check that I wasn't letting a bug thru 🤞

dsamojlenko commented 4 years ago

It's because the route we use for the Start Over link that clears the session data is a unilingual link: /clear.

When you use the browser back button, it doesn't actually change your language back, it just renders the previous page from cache. So when you hit /clear and get redirected to /, your session language is still French.

Should be an easy fix - just create multiple clear routes (in the global controller). I'd leave the existing one, but add /en/clear and /fr/clear ... they would all have the same action (set session to null, redirect to /)

Then again, now that I think of it, maybe even easier - the Start route also clears the session. Rather than having the Start Over link use the /clear route, you could just use the named start route.

courtneycl commented 4 years ago

Something that IS happening on prod:

  1. Start now
  2. Answer a few questions to get a far down paths
  3. Switch language to French
  4. Click retour
  5. Observe the same page switch languages to English. Expected we would see the previous question in French.

Is this a separate bug?

dsamojlenko commented 4 years ago

oh yeah, so because our Back button is just hooking into the browser's history stack, this is similarly expected behaviour - it's like if you're on any page, hit the Français link, then hit browser back, you'll be looking at an English page, because that's the last thing in your history. Our back link works the exact same way.

hmmm... we've got a longstanding item to revisit how the back link works. I'm not sure what the solution will be. We hooked into the browser history stack because it's the easiest implementation - the browser always knows where you came from.

The challenge in implementing a back button in our case, is we're not always sure where the user came from - could be different depending on answers to previous questions... but it's something we do want to figure out.