Avoid complex :not() selector in copy_code behavior

What does this MR do and why?

Fixes a client-side SyntaxError thrown by document.querySelector('.file-content.code:not(.blob-embed *)') in copy_code.js.

  • Root cause: The selector ':not(.blob-embed *)' requires Chrome 88+. The original code was introduced in commit 67a082939963.
  • Fix: Replace the querySelector call with [...document.querySelectorAll('.file-content.code')].some((el) => !el.closest('.blob-embed')). Behavior is identical — raw file views are still detected, blob-embed pages still excluded — but the replacement parses on all browsers.
  • Scope: Affected browsers are below GitLab's supported-browser floor; this is a hardening fix to stop Sentry noise and restore full main.js initialization on old WebViews, not a supported-browser commitment.

References

Screenshots or screen recordings

No UI change — this is a non-visual JavaScript fix. The copy-code button appearance and behavior are identical for all supported browsers.

How to set up and validate locally

  1. Check out this branch and run gdk start.
  2. Open a Markdown file or snippet that renders a code block (e.g. any project wiki page or a snippet at /-/snippets). Confirm that copy-code buttons appear as expected.
  3. Visit a raw blob view (e.g. https://gitlab.example.com/<group>/<project>/-/raw/<branch>/README.md). Confirm no copy-code buttons or mutation observer are active on that page.
  4. Run the Jest spec: yarn jest spec/frontend/behaviors/copy_code_spec.js — all tests should pass.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Risk is low: the change is a drop-in selector replacement with identical semantics, covered by the existing Jest suite. No new dependencies, no database migrations, no feature flags required.

Edited by Chaoyue Zhao

Merge request reports

Loading
Loading