Only init empty project tabs that are on the page
What does this MR do and why?
The empty project page renders two tab navs that may not exist, depending on user permissions and admin settings:
.js-configure-git-tabs(Local / Global Git config) renders only when the user can push code..js-empty-project-tabs(SSH / HTTPS clone instructions) renders only when the user can push code and SSH is enabled. When SSH is disabled, the HTTPS instructions render without tabs.
app/assets/javascripts/pages/projects/show/empty_project.js queried both selectors unconditionally and passed each result to GlTabsBehavior. When a nav did not exist, the constructor received null and threw Error('Cannot instantiate GlTabsBehavior without an element'). The throw happens in the page entrypoint, so the error is uncaught.
In CI this logged the error in 5 examples across 2 spec files:
spec/features/projects/show/repository_actions_spec.rb(empty public project, signed out or signed in)spec/features/admin/admin_disables_git_access_protocol_spec.rb(SSH disabled)
This MR filters the query results to the elements that exist before creating the tab behavior. Nothing else changes.
Changes made:
app/assets/javascripts/pages/projects/show/empty_project.js— instantiateGlTabsBehavioronly for navs that are on the pagespec/frontend/pages/projects/show/empty_project_spec.js— new spec with three cases: both navs present, only the Git config nav present, no navs present. It stubsCSS.escapebecause jsdom lacks it, the same wayspec/frontend/tabs/index_spec.jsdoes.
How to set up and validate locally
- Create a new blank project without a README so it is empty. Make it public.
- Open the empty project while signed out. Check the DevTools console has no
GlTabsBehaviorerror. - Sign in as an admin. Go to Admin > Settings > General > Visibility and access controls. Set "Enabled Git access protocols" to "Only HTTP(S)". Open the empty project again. Check the console is clean and the HTTPS instructions still render.
- Restore the setting to the default. Check the SSH / HTTPS tabs still switch.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
- I have evaluated the MR acceptance checklist for this MR.
References
- Addresses one entry of #628901 (browser console error catalogue, section B)
- Errors surfaced by !255207 (closed) (feature specs fail on console errors)
- Sibling fixes from the same catalogue: !255305 (merged), !255309 (merged), !255311 (merged)