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 — instantiate GlTabsBehavior only for navs that are on the page
  • spec/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 stubs CSS.escape because jsdom lacks it, the same way spec/frontend/tabs/index_spec.js does.

How to set up and validate locally

  1. Create a new blank project without a README so it is empty. Make it public.
  2. Open the empty project while signed out. Check the DevTools console has no GlTabsBehavior error.
  3. 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.
  4. 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.

References

🤖 Generated with Claude Code

Edited by Miguel Rincon

Merge request reports

Loading
Loading