Fix file tree links missing relative URL root
What does this MR do and why?
The file tree browser sidebar built each link with new URL() and an absolute path. That dropped the relative URL root (for example /gitlab) from gon.gitlab_url. On instances served under a relative URL root, opening a file or folder in a new tab, middle-clicking, or copying the link gave a 404. Normal left-click worked because the Vue router base already has the root. This MR prepends gon.relative_url_root to the path for both directory and file links, and adds a Jest test for it.
References
- Resolves #603084
Regression
- This bug came in with the feature that added "open in a new tab" support to the repository file tree. It was not an edit to old code.
- That feature merged in 18.9 in !219565 (merged). Its commit built the
hrefwithout the relative URL root. - The whole file tree browser sat behind the
repository_file_tree_browserfeature flag. - Flag timeline: added in 18.0, default off (!189445 (merged)); set to
default: truein 18.9 (!220668 (merged)); removed in 19.2 (!241090 (merged)). - The flag was already on by default when the feature shipped, so the broken link reached everyone from 18.9.
- Removing the flag in 19.2 made it unconditional. A user on 19.2.1 hits it and cannot turn it off.
Screenshots or screen recordings
| Before | After |
|---|---|
| Hovering a file tree link on a relative-root instance shows a URL without the context path; opening it in a new tab returns 404. | The link includes the context path and opens correctly in a new tab. |
UI behavior only; no visual change to capture.
How to set up and validate locally
-
Serve GDK under a relative URL root, then restart:
gdk config set relative_url_root /gitlab gdk reconfigure gdk restartGDK now serves GitLab at
http://127.0.0.1:3000/gitlab. -
Open any repository and, in the left-hand "Files" tree, browse into a directory.
-
Hover a file or directory link and confirm the URL in the status bar includes the
/gitlabcontext path. -
Open it in a new tab (middle-click or Cmd/Ctrl-click). It should load the file or directory. Before this fix the URL dropped
/gitlaband returned a 404.
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.