Skip to content

fix(dropzone): prevent dropzone exception if target element missing

What does this MR do?

When a users opens the New Merge Request page (e.g. https://gitlab.com/gitlab-org/gitlab/merge_requests/new), he sees following error message in the browser console:

sentry.8f98135a.chunk.js:1 Uncaught Error: No Dropzone found for given element. This is probably because you're trying to access it before Dropzone had the time to initialize. Use the `init` option to setup any additional observers on your Dropzone.
    at Function.i.forElement (commons~pages.groups.epics.index~pages.groups.epics.show~pages.groups.milestones.edit~pages.groups.m~b7d7bc7f.d5a175f4.chunk.js:1)
    at v (pages.projects.merge_requests.creations.new.5386921d.chunk.js:1)
    at e.value (pages.projects.merge_requests.creations.new.5386921d.chunk.js:1)
    at new e (pages.projects.merge_requests.creations.new.5386921d.chunk.js:1)
    at HTMLDocument.t.a (pages.projects.merge_requests.creations.new.5386921d.chunk.js:1)
    at HTMLDocument.r (sentry.8f98135a.chunk.js:1)

This error is caused by the fact, that the branch compare view (app/views/projects/merge_requests/creations/_new_compare.html.haml) doesn't have the required template to support Dropzone.js ,while the submit view (app/views/projects/merge_requests/creations/_new_submit.html.haml) does. Nevertheless, the dropzone initialisation is called in both cases, without checking if the target element actually there. Adding a simple guard around the initialisation solves this, hence the error in the browser console is gone.

This exception is responsible for the majority of JS exceptions within our GitLab instance (measured via Sentry).

🔧 with at Siemens

Closes #25901 (closed)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Fabio Huser

Merge request reports