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

report: workaround google3 fragment link bug #13016

Closed
wants to merge 2 commits into from

Conversation

connorjclark
Copy link
Collaborator

replacing #12995

basically option 3 from #12995 (comment) , but undoing the change such that ReportGenerator is not necessary.

I considered only having _fixFragmentLinks called when necessary, but it's nice to have this code exercised in all reports because it means we'll notice quicker if it ever breaks.

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

  1. click handler: wrapper.addEventListener('click', () => window.location.href = category.id). Downsides:

    • we should avoid overriding default behavior when possible (let a link be a link). Arguably setting fully qualified links (option 1) is the semantically correct thing to do when we can't rely on the <base> url rather than setting a relative fragment url and overriding the behavior on click anyways.

I think theres another alternative that I didnt see in that discussion. (very possible i didnt look far, tho).. cc @brendankenny since you were innit

we use preventDefault and scrollIntoView:

document.querySelectorAll('a.lh-gauge__wrapper[href^="#"]').forEach(elem => {
    elem.addEventListener('click', e => {
        e.preventDefault();
        const target = document.querySelector(elem.getAttribute('href')); // .href would be fully qualified...
        target.scrollIntoView();
          
    })
})

by default.. this wouldn't update the URL.. but we could still allow that (in certain scenarios if we we wanted) by adding this into the handler.

        const url = new URL(elem.getAttribute('href'), location.href)      
        history.pushState({}, '', url);

scrollIntoView is totes magic... that direction seems a lot more promising to me.

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

Successfully merging this pull request may close these issues.

4 participants