Loading
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 commit67a082939963. - Fix: Replace the
querySelectorcall 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.jsinitialization on old WebViews, not a supported-browser commitment.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/629438
- Duo Sentry triage note that identified and suggested this fix: https://gitlab.com/gitlab-org/gitlab/-/work_items/629438#note_3865340086
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
- Check out this branch and run
gdk start. - 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. - 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. - 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