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

Make sticky header implementation more robust #10663

Open
MisRob opened this issue May 9, 2023 · 2 comments
Open

Make sticky header implementation more robust #10663

MisRob opened this issue May 9, 2023 · 2 comments
Labels
APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: frontend TAG: tech update / debt Change not visible to user

Comments

@MisRob
Copy link
Member

MisRob commented May 9, 2023

For topic pages, we implemented a logic

stickyCalculation() {
const header = this.$refs.header && this.$refs.header.$el;
const topbar = document.querySelector('.scrolling-header');
const headerBottom = header ? header.getBoundingClientRect().bottom : 0;
const topbarBottom = topbar ? topbar.getBoundingClientRect().bottom : 0;
if (headerBottom < Math.max(topbarBottom, 0)) {
this.sidePanelStyleOverrides = {
position: 'fixed',
top: `${Math.max(0, headerBottom, topbarBottom)}px`,
height: '100%',
};
} else {
this.sidePanelStyleOverrides = {};
}
},

that makes the sidebar sticky

sticky

The main idea of the current implementation is based on switching the sidebar between position: absolute and position: fixed. However, this approach, under certain circumstances (presence of the sidebar, page height), seems to be the main culprit of the jumping scrollbar problem described in #10414 (which contains a somewhat fragile solution).

In the past, we used a different approach where we didn't switch position but re-calculated the top position

stickyCalculation() {
let header = document.getElementsByClassName('header')[0];
let topbar = document.getElementsByClassName('ui-toolbar')[0];
if (header) {
let position = header.getBoundingClientRect();
let topbarPosition = topbar.getBoundingClientRect();
if (position.bottom >= 64) {
this.stickyTop = `${position.bottom}px`;
} else if (position.bottom < 0 && topbarPosition.bottom < 0) {
this.stickyTop = '0px';
} else {
this.stickyTop = '64px';
}
} else {
null;
}
},

however, that was one of the causes of the header being torn away from the sidebar completely (#8627) or temporarily which could be seen as the sidebar updating its position with delay, causing observable gaps between the sidebar and the header, as it took some time for the browser to re-render sidebar's top position.

Lastly, the current implementation is not very efficient as styles are re-calculated with each scroll event. There's throttling which helps, however, it could be improved further as there's no need to re-calculate styles under some conditions, for example when the sidebar is in its sticky state and we're scrolling down, we know that no change is needed.

It'd be good to think about a more robust and efficient approach that would also avoid the pitfalls of our previous implementation.

@MisRob MisRob added TAG: tech update / debt Change not visible to user APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: frontend labels May 9, 2023
@MisRob
Copy link
Member Author

MisRob commented May 9, 2023

If we're going to move towards IE11 deprecation, one way to go would be using native position: sticky. I assume that the main reason for implementing our custom logic was that position: sticky is no supported in IE11.

@MisRob
Copy link
Member Author

MisRob commented May 9, 2023

Depending on the complexity of the new solution, it may be done as part of #10415 or after. I wanted to experiment with some different approaches originally that would require page layout changes and found it difficult due to issues described in #10415.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Learn Re: Learn App (content, quizzes, lessons, etc.) DEV: frontend TAG: tech update / debt Change not visible to user
Projects
None yet
Development

No branches or pull requests

2 participants