Why is stateMapping.stateToRoute()
called after a UI refresh triggered by the popstate
event?
#4633
Unanswered
JJWesterkamp
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using the history router, I'm having trouble getting the right state in the URL after
popstate
events. To show you what I mean I created logging of the data that goes instateMapping.stateToRoute()
and instateMapping.routeToState()
and also their return values on each invocation with a method decorator (the factory of which I calltraced
):This results in a log such as in the following image:
I have used this to see whether the states are converted properly, and in all cases both my implementations of
routeToState
andstateToRoute
work as they should.Problem:
After clicking the browser back-button the
popstate
event fires, and that triggers, as expected, a uiState update,routeToState
is called, and my log shows that the new UI state returned by it is from my view correct. But shortly after that alsostateToRoute
is called. See below screenshot of this event:This screenshot shows that the
UiState
that is used as input for the newRouteState
does not match theUiState
generated byrouteToState
before, resulting in the wrong URL for the current UI state, probably because theRouteState
that is generated from it does pass an equality test against the currently activeRouteState
. To be specific, theUiState
used to generate the newRouteState
should not have thesortBy
setting, as theUiState
generated from the sourceRouteState
shows.Question 1
Should the history router get a new state to process in the first place after a
popstate
event? As far as I understand, the route state in the new 'current' history entry should be the source of truth, and it already is the new state for the application.Question 2
Why do I see that the
UiState
s don't match? Is this a bug? And if not, what am I doing wrong / misunderstanding?Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions