Fix JavaScript path helpers for browsers without Array.at

What does this MR do and why?

Fixes a TypeError: t.at is not a function crash reported by Sentry that breaks blob page rendering for users on browsers without Array.prototype.at().

Root cause: The generated JavaScript path helper utils (app/assets/javascripts/lib/utils/path_helpers/utils.js) used Array.prototype.at(-1) in three places (resolveOrganizationScope, withoutOrganizationPathOption, and splitProjectFullPath). Array.prototype.at() is Baseline 2022 (Chrome 92+). On browser engines without it, the first call throws during blob-page Vue router setup (createRouter → projectPath → splitProjectFullPath), so the file tree, last-commit, and header apps all fail to mount.

Fix: Replace the three .at(-1) calls with index-from-end access (arr[arr.length - 1]), which is universally supported and needs no polyfill. This is a minimal, behavior-identical change.

Because utils.js is auto-generated (DO NOT modify it manually), the real change is in the generator template lib/gitlab/js_routes.rb (javascript_utils); utils.js is regenerated to match and stays in sync with the CI check added in the same originating commit.

Verification:

  • Rendered the javascript_utils template standalone and confirmed it is byte-identical to the committed utils.js.
  • node_modules/.bin/jest spec/frontend/lib/utils/path_helpers/ → 9 suites, 177 tests passed.
  • Direct edge-case coverage of splitProjectFullPath (the crashing path): nested paths, single-segment, empty, and non-string input all behave correctly.

References

Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/629950

Screenshots or screen recordings

N/A — internal JavaScript utility change, no UI change.

How to set up and validate locally

  1. Run the frontend specs:
    node_modules/.bin/jest spec/frontend/lib/utils/path_helpers/
  2. Confirm the generated helpers are in sync with the generator:
    bin/rake gitlab:js:routes
    git diff --exit-code app/assets/javascripts/lib/utils/path_helpers/

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading
Loading