Skip to content

New navigation breaks commit pages in several ways

If you visit a commit page (e.g., gitlab-ui@c95606f6) with the new navigation enabled, several things break:

Old navigation New navigation
Screenshot_2023-02-21_at_16-29-46_chore_deps__update_dependency__babel_core_to__7.21.0__c95606f6____Commits___GitLab.org___gitlab-ui___GitLab Screenshot_2023-02-21_at_16-29-31_chore_deps__update_dependency__babel_core_to__7.21.0__c95606f6____Commits___GitLab.org___gitlab-ui___GitLab
  • The commit details never seem to load.
  • The header bar for the first file is split/broken.
  • The code is not syntax highlighted correctly.
  • The diff stat and file selector are missing.

It might be that something is checking for the offsetHeight of the old top nav, and doesn't handle it not being found, causing some script to abort early? If that's the case, it's feasible this affects other pages as well.

Cause

This is caused by app/assets/javascripts/pages/projects/commit/show/index.js#L23 where we attempt to retrieve the topbar's offsetHeight without ensuring that the topbar actually exists. We do similar operations in several places, but we generally abort the execution if the querySelector fails to find the topbar.

Solution

We should be able to quickly fix the affect place(s) by leveraging the optional chaining operator and falling back to a height of 0 when the topbar is not rendered.

Edited by Paul Gascou-Vaillancourt