mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.24k stars 141 forks source link

Multiple location changes from routing middleware when URL contains escaped sequences #297

Closed uhfath closed 2 years ago

uhfath commented 2 years ago

Here is a repro. To reproduce:

  1. open development console;
  2. navigate to "Counter" page;
  3. clear console;
  4. enter Test in the input box and press enter;
  5. note the console log showing the sequence of events: SAVE -> PARAMS -> LOCATION;
  6. reload the page;
  7. note the sequence: INIT -> PARAMS;
  8. clear the console again;
  9. now edit the input box with some international text like Тест (this one is in Russian language, so just copy-paste) and press enter;
  10. not the change in sequence: SAVE -> PARAMS -> LOCATION (2) (called two times);
  11. reload the page;
  12. note the sequence: INIT -> PARAMS -> LOCATION;

The issue is 10 and 12. In 10 there should be only one location change just like in 5. And in 12 there should be no location change at all, just like in 7.

Double location changes lead to multiple records in browser history so when a user presses back he is not navigated actually back in history because history is doubled and sometimes tripled.

My guess is that the issue is this: https://github.com/mrpmorris/Fluxor/blob/97997c704a69c346f692c06b475b0be472c03c61/Source/Fluxor.Blazor.Web/Middlewares/Routing/Effects.cs#L20

The Uri might be unescaping the URL it contains whereas NavigationManager.Uri returns it as escaped sequence. Hence the difference.

Perhaps something like this would be better?

var isUriSame = string.Equals(uri.TrimEnd('/'), NavigationManager.Uri.TrimEnd('/'), StringComparison.OrdinalIgnoreCase)

In this case any irrelevant differences won't trigger location changing.