Initialize route state in store before fetching groups #6614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The behavior of
GroupsService.load
varies depending on whether the current route is the sidebar or not. During sidebar startup,GroupsService.load
was called beforeRouterService.sync
. As a result the route wasnull
during the initial call toGroupsService._loadGroupsForUserAndDocument
and hence the service did not execute the sidebar-specific code path to wait for the document URI to become known at that point.During the first
GroupsService._loadGroupsForUserAndDocument
call,_setupAutoReload
would set up a watcher that would react to changes instore.mainURI()
. This watcher would fire after the main guest frame connects. Depending on when that happens, requests from the initialGroupsService.load
request could still be in-flight. If the second set of groups API calls completed first, followed by the first set of groups API calls, then the final set of loaded groups might reflect the first call toGroupsService.load
, where the document URI was not used (because the route was unknown).This commit fixes the issue by re-arranging the sidebar startup sequence to initialize the router service before other services.
Fixes https://github.com/hypothesis/support/issues/79
Testing:
See steps to reproduce in https://github.com/hypothesis/support/issues/79#issuecomment-2413707975. The issue should reproduce on the
main
branch but not on this branch.