Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RUMF-868] ignore paramaters stored in the hash #792

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,17 @@ describe('rum track location change', () => {

expect(createSpy).not.toHaveBeenCalled()
})

it('should not create a new view when the search part of the hash changes', () => {
history.pushState({}, '', '/foo#bar')
const { lifeCycle } = setupBuilder.build()
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, createSpy)

history.pushState({}, '', '/foo#bar?search=1')
history.pushState({}, '', '/foo#bar?search=2')
history.pushState({}, '', '/foo#bar?')
history.pushState({}, '', '/foo#bar')

expect(createSpy).not.toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function trackLocationChanges(onLocationChange: () => void) {
export function areDifferentLocation(currentLocation: Location, otherLocation: Location) {
return (
currentLocation.pathname !== otherLocation.pathname ||
(!isHashAnAnchor(otherLocation.hash) && otherLocation.hash !== currentLocation.hash)
(!isHashAnAnchor(otherLocation.hash) &&
getPathFromHash(otherLocation.hash) !== getPathFromHash(currentLocation.hash))
)
}

Expand Down Expand Up @@ -49,3 +50,8 @@ function isHashAnAnchor(hash: string) {
const correspondingId = hash.substr(1)
return !!document.getElementById(correspondingId)
}

function getPathFromHash(hash: string) {
const index = hash.indexOf('?')
return index < 0 ? hash : hash.slice(0, index)
}