Read $router in GlLink only when the link needs it
What does this MR do?
GlLink and BLink read $router before they check to and disabled. A plain link with only href still reads $router.
With Vue 2, the $router getter can throw. VueRouter adds it to Vue.prototype when it is installed. The getter reads this._routerRoot._router, and _routerRoot is undefined on an instance that did not get the router's beforeCreate hook. In GitLab, the Vue 2 duo_panel bundle installs VueRouter after page apps mount. A GlLink that the page app created before that install, such as the link in the Observability feedback GlPopover, then renders as <!---->.
This MR checks disabled and to first, then $nuxt, then $router. A link reads $router only when it can be a router link:
GlLink: thetagcomputed.BLink: the vendoredcomputeTag.
$nuxt comes before $router because Nuxt also installs $router.
The result is the same for every app that can exist. One state changes: $nuxt without $router gave an anchor and now gives nuxt-link. That state cannot happen, because every Nuxt app has a router.
How it was verified
- The new spec mounts
GlLinkwith a$routergetter that throws. Onmainit fails withVUE_VERSION=2andVUE_VERSION=3. With this change it passes in both. - All link and router specs pass in both Vue versions.
- End to end in GDK, on the group Observability page with
vue3_migrate_duo_paneloff. A Playwright script delays the Vue 2duo_panelbundle by 3 s, so the page app mounts before VueRouter installs:- On
main, the popover link is missing and Vue logsrender GlLink: Cannot read properties of undefined (reading '_router'). This is the error from the issue. - With this change, the link renders and no error is logged.
- In both runs, a
GlLinkwithtounder a realVueRouterstill rendersrouter-link.
- On
The bug depends on load timing. Without the delay, GDK creates the GlLink just after the router install, and the bug does not show. Details: !6541 (comment 4056076112)
Screenshots or screen recordings
The Observability feedback popover in GDK, with the duo_panel bundle delayed:
Before (main) |
After (this MR) |
|---|---|
![]() |
![]() |
Integrations
- GitLab: not needed, no API change. The fix reaches GitLab with the next
@gitlab/uibump.
References
- Fixes the
GlLinkfailure reported in gitlab-org/gitlab#634928 (closed) (Vue 2duo_panelinstalls VueRouter after page apps mount) - Findings and the limits of this fix: gitlab-org/gitlab#634928 (comment 4056037495)
- Nuxt check order, from review: !6541 (comment 4056145462)
- Same pattern, lazy router-link resolution: !6527 (merged)
- Load order change that exposed the bug: gitlab-org/gitlab!252293 (merged)

