Skip to content

Commit

Permalink
STCOR-950 Added location to a hook in <MainNav> to fix comparing …
Browse files Browse the repository at this point in the history
…old `location` value (#1600)

## Description
After the switch to hooks, in
[stripes-core/src/components/MainNav/MainNav.js at
3570eea ·
folio-org/stripes-core](https://github.com/folio-org/stripes-core/blob/3570eea0bca50bb0abb0cc0e52db3ae4bc3a792e/src/components/MainNav/MainNav.js#L46)
`location` object is not updated, and so `store.subscribe` callback
always uses an old value.

When `updateLocation` compares `cleanStateQuery` and
`cleanLocationQuery` objects, they are always different because we’re
comparing to an old `location`

This caused a bug in Inventory, where when a user opens a shared record
- the page reloads and user is taken back to search results. This
happens because when a user opens a shared record we append
`shared=true` to the url. And because `<MainNav>` doesn't compare to a
current url the flow gets interrupted.

If we add location to the hook’s deps it works as expected.

## Screenshots


https://github.com/user-attachments/assets/0973c2ab-c915-4d99-b062-b62c07eb9308


## Issues
[STCOR-950](https://folio-org.atlassian.net/browse/STCOR-950)
  • Loading branch information
BogdanDenis authored Feb 24, 2025
1 parent 18b82a3 commit d0fca16
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* *BREAKING* replace useSecureTokens conditionalsRefs STCOR-922.
* Set tenant context based on authentication response with overrideUser parameter on login (Eureka, ECS - Single tenant UX) STCOR-946.
* Omit leading slash in paths passed to `ky` in `useModuleInfo`. Refs STCOR-949.
* Added `location` to a hook in `<MainNav>` to fix comparing old `location` value. Fixes STCOR-950.

## [10.2.0](https://github.com/folio-org/stripes-core/tree/v10.2.0) (2024-10-11)
[Full Changelog](https://github.com/folio-org/stripes-core/compare/v10.1.1...v10.2.0)
Expand Down
2 changes: 1 addition & 1 deletion src/components/MainNav/MainNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const MainNav = () => {
return () => {
_unsubscribe();
};
}, []); // eslint-disable-line
}, [location]); // eslint-disable-line

// if the location changes, we need to update the current module/query resource.
// This logic changes the visible current app at the starting side of the Main Navigation.
Expand Down

0 comments on commit d0fca16

Please sign in to comment.