Fix TypeError in repository router afterEach hook
What does this MR do and why?
Fixes a TypeError: Cannot read properties of undefined (reading 'includes') in the repository file browser, reported via Sentry.
What breaks. The router has no catch-all route. Browser history navigation can land on a non-repository path (e.g. /-/wikis/home) while the app is mounted. No route matches, so the route name is undefined. The afterEach hook calls name.includes('blobPath') and throws, leaving the Web IDE path and document title stale.
Fix. Add a named, render-nothing catch-all as the last route:
{
path: '*',
name: 'notFound',
component: { render: () => null },
},Every navigation now resolves to a named route, so name is always a string. This removes the whole class of undefined-name bugs without guarding individual call sites.
This also fixes a second latent bug: when no route matched, classList.toggle('repository-max-width', undefined) acted as a plain toggle instead of forcing the class off, so the wide-layout class could be wrongly re-added.
Why not redirect: '/'. That would rewrite the URL when the user navigates to a real non-repository page. The render-null component keeps output identical to before — nothing rendered.
Verification. Regression spec added; suite passes under both Vue 2 and Vue 3.
References
- Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/629948 (Sentry: TypeError: Cannot read properties of undefined (reading 'includes'))
- Introduced by 41909a8c ("Move setTitle into router")
Screenshots or screen recordings
Not applicable — this fixes a client-side JS exception with no visible UI change.
How to set up and validate locally
- Run the spec under Vue 2 and Vue 3:
yarn jest spec/frontend/repository/router_spec.js VUE_VERSION=3 yarn jest spec/frontend/repository/router_spec.js - In GDK, open a project's repository file browser and navigate via browser history to a non-repository path (e.g.
/-/wikis/home). Before the fix the console shows the TypeError and the Web IDE path goes stale; after the fix navigation completes cleanly.
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.