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: the tag computed.
  • BLink: the vendored computeTag.

$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 GlLink with a $router getter that throws. On main it fails with VUE_VERSION=2 and VUE_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_panel off. A Playwright script delays the Vue 2 duo_panel bundle by 3 s, so the page app mounts before VueRouter installs:
    • On main, the popover link is missing and Vue logs render 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 GlLink with to under a real VueRouter still renders router-link.

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)
before after

Integrations

  • GitLab: not needed, no API change. The fix reaches GitLab with the next @gitlab/ui bump.

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading