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

SDK: better support for SPA routing - STEP 2/2 : filter out html anchor tags changes #466

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1c11c6e
add hash tracking
mquentin Jul 22, 2020
41dec89
✅ add hash change tests
mquentin Jul 22, 2020
f5565c2
introduce renewViewOnChange
mquentin Jul 22, 2020
72ae621
add better management and comments of the areViewDifferent hash part
mquentin Jul 22, 2020
571e702
set async tests for hashchanges
mquentin Jul 23, 2020
fc6d677
reset window.location.hash of previous tests
mquentin Jul 23, 2020
97192a5
skip tesst using Promise for IE
mquentin Jul 23, 2020
9383bf1
replace jasmine promise with callback process
mquentin Jul 27, 2020
0e2d6b5
remove anchor check on this PR
mquentin Jul 27, 2020
19bc93f
add anchor nav filter
mquentin Jul 27, 2020
a86a41c
patch tslint error
mquentin Jul 27, 2020
52aafd5
✅ and implem reviews
mquentin Jul 28, 2020
29d6312
implement reviews regarding func naming and hash cleaning
mquentin Jul 28, 2020
e593a8c
Merge branch 'maxime.quentin/betterSupportForSPAroutingAddhashTrackin…
mquentin Jul 28, 2020
27b6d52
simplify mockGetElementById
mquentin Jul 28, 2020
5bd0103
Merge branch 'master' into maxime.quentin/betterSupportForSPAroutingF…
mquentin Jul 28, 2020
4cee0ad
Merge branch 'maxime.quentin/betterSupportForSPArouting' into maxime.…
mquentin Jul 28, 2020
07ba398
add e2e tests
mquentin Jul 30, 2020
f282a53
simply anchor filter out proccess
mquentin Jul 30, 2020
2063209
implement reviews
mquentin Jul 30, 2020
ed4f9be
unit test the hash change acknowledgement after an anchor nav
mquentin Jul 30, 2020
9336bce
fix typo
mquentin Jul 30, 2020
1f809c3
fix typo v2
mquentin Jul 30, 2020
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
10 changes: 6 additions & 4 deletions packages/rum/src/viewCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function startViewCollection(location: Location, lifeCycle: LifeCycle) {
currentView.end()
currentView = newView(lifeCycle, currentLocation, ViewLoadingType.ROUTE_CHANGE)
} else {
// Anchor navigations would modify the location without generating a new view.
// These changes need to be acknowledged so they don't interfer with the next change areDifferentViews call
mquentin marked this conversation as resolved.
Show resolved Hide resolved
currentLocation = { ...location }
mquentin marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down Expand Up @@ -176,13 +178,13 @@ function trackHash(onHashChange: () => void) {
window.addEventListener('hashchange', monitor(onHashChange))
}

function isAnchorHashInPage(hash: string) {
const cleanedHash = hash.substr(1)
return !!document.getElementById(cleanedHash)
function isHashAnAnchor(hash: string) {
const correspondingId = hash.substr(1)
return !!document.getElementById(correspondingId)
}

function areDifferentViews(previous: Location, current: Location): boolean {
return previous.pathname !== current.pathname || (!isAnchorHashInPage(current.hash) && previous.hash !== current.hash)
return previous.pathname !== current.pathname || (!isHashAnAnchor(current.hash) && previous.hash !== current.hash)
}

interface Timings {
Expand Down
8 changes: 1 addition & 7 deletions test/e2e/scenario/agents.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ describe('user action collection', () => {

describe('anchor navigation', () => {
it('should not create a new view when it is an Anchor navigation', async () => {
await $('#test-anchor')

await browserExecute(() => {
window.location.hash = '#test-anchor'
})
await $('#test-anchor').click()

await flushEvents()
const rumEvents = await waitServerRumEvents()
Expand All @@ -288,8 +284,6 @@ describe('anchor navigation', () => {
})

it('should create a new view on hash change', async () => {
await $('#test-anchor')

await browserExecute(() => {
window.location.hash = '#bar'
})
Expand Down