Google search: Check for metatags before assigning object property
What does this MR do and why?
Fixes a bug with search when returning a result without any indexed metatags.
There are rare cases where Google can return a result with an empty pagemap.metatags
object. This example search might still show this: https://docs.gitlab.com/search/?q=gitlab%20flow&page=1 ("Error fetching results. Please try again later.")
In this case, the "GitLab Flow" page that causes the error no longer exists on the site, but it's still in Google's index. This is a known possibility; Google's index may sometimes be out of sync with the site temporarily, and the way we do client-side redirects might be a factor as well (#1387).
What's surprising is that it comes back as a result but with empty metatags, but that's not something we can fix on our side. So, for now, we can at least not return an error if this happens. This MR explicitly checks for metatags before trying to use them, preventing the error.
Screenshots, screen recordings, or links to review app
before | after |
---|---|
How to validate
Numbered steps to set up and validate the change are strongly suggested.
-
Search for "flow" on the live site: https://docs.gitlab.com/search/?q=flow&page=1 (this will likely return an error) -
Search for "flow" on the review app: https://gps-pagemap-empty.docs.gitlab-review.app/search/?q=flow&page=1 (no error, but the top result goes to a 404; we'll investigate further in a follow-up)
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.