Guard against undefined data in blob viewer Apollo handlers

What does this MR do and why?

Adds guard against undefined data in two places in blob viewer:

  1. result({ data }) hook for the blobInfo query can be called with undefined data. according to https://gitlab.com/gitlab-org/gitlab/-/work_items/625054, this error hit 114,415 events affecting 110,907 users in approximately one day
  2. adding fallback { } value in update hook

References

Screenshots or screen recordings

No visible UI change — this is a defensive guard only. The table below shows that blob pages continue to work correctly after the fix (rich viewer README, source toggle, JS file with syntax highlighting, line-hash navigation, blame view).

Before After
No visual change (defensive guard)

How to set up and validate locally

  1. Start GDK.
  2. Visit a blob page, for example http://gdk.test:3000/flightjs/Flight/-/blob/master/README.md.
  3. Toggle between Code and Preview views and confirm the content renders without errors.
  4. Visit a code file (e.g. a .js file) and verify syntax highlighting works.
  5. Append #L20 to the URL and confirm the page scrolls to and highlights the correct line.
  6. Open the Blame view and confirm it loads correctly.
  7. Check the browser console — confirm no TypeError: Cannot read properties of undefined (reading 'project') appears.
  8. Run the unit tests:
yarn jest spec/frontend/repository/components/blob_content_viewer_spec.js

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.

Edited by Chaoyue Zhao

Merge request reports

Loading
Loading