Skip to content

Conversation

@KaiVandivier
Copy link
Collaborator

@KaiVandivier KaiVandivier commented Apr 14, 2025

DHIS2-19412

If an app is using its app root / as base for hash routing, before this fix, new navigations in the app will trigger an update to pluginHref, which can then set the app's URL to /index.html?redirect=false, which can cause a whole-app reload, since it's a different path than before. This change checks for equivalent base paths, and if they are equivalent, only updates the iframe location's hash, if it has changed

Tested with a build of the new maintenance app from this PR: dhis2/maintenance-app-beta#541

equiv-test-routing.mov

Also tested these scenarios:

  • Maintenance preview
  • Opening links in new tabs/copying and pasting
  • Deep links
    • Agg DE
    • Capture
  • Forward/back
  • Command palette
    • App links
    • Shortcuts
  • System settings
  • Analytics:
    • Hash routing in ER, DV, Maps, Dashboard
    • Opening event reports
    • “Open as map”
    • Manual URL changes
  • Other header-bar links (messaging, interpretations)
  • User profile menu

@sonarqubecloud
Copy link

@KaiVandivier KaiVandivier requested a review from amcgee April 14, 2025 16:03
Comment on lines +110 to +124
// Copy before mutating
const [currentUrl, newUrl] = [new URL(currentUrlOrig), new URL(newUrlOrig)]
newUrl.searchParams.sort()
// If redirect is not already false in the search set that
currentUrl.searchParams.set('redirect', 'false')
currentUrl.searchParams.sort()
// If pathname doesn't end in html, add that
if (currentUrl.pathname.endsWith('/')) {
currentUrl.pathname = currentUrl.pathname + 'index.html'
}

const [newBase] = newUrl.href.split('#')
const [currentBase] = currentUrl.href.split('#')

return newBase === currentBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be more restrictive than it needs to be - we could probably just check for any sub-path of the base url - but I tested this and it works well!

@amcgee amcgee merged commit eef989d into main Apr 14, 2025
5 checks passed
dhis2-bot added a commit that referenced this pull request Apr 14, 2025
## [1.7.6](v1.7.5...v1.7.6) (2025-04-14)

### Bug Fixes

* test URL equivalency before replacing iframe location to avoid reloads ([#46](#46)) ([eef989d](eef989d))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 1.7.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants