Skip to content

Fix: Potential TypeError in distance.element.js due to missing null/undefined check on line_model #686

Description

@AkshatRaj00

Description

In app/components/selection/distance.element.js, the position setter directly passes line_model to this.styleProps and this.render() without verifying if line_model exists.

If line_model is unexpectedly passed as null or undefined (which can happen during rapid mouse movements or when elements dynamically unmount in modern single-page applications), the application will crash with a TypeError during object destructuring in downstream setters/methods.

Code Location

In app/components/selection/distance.element.js:

set position ({ line_model, node_label_id }) {
  this.styleProps = line_model
  this.$shadow.innerHTML = this.render(line_model, node_label_id)
}
Suggested Fix
Add a guard clause at the beginning of the position setter to gracefully exit if line_model is falsy:

JavaScript
set position ({ line_model, node_label_id }) {
  if (!line_model) return
  
  this.styleProps = line_model
  this.$shadow.innerHTML = this.render(line_model, node_label_id)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions