Skip to content

LengthMeasurement: setting mode to 'edge' while disabled shows the snap marker #871

Backlog

Description

@berchri

Describe the bug 📝

ThatOpen snap marker shows on a disabled LengthMeasurement

Minimal reproduction for @thatopen/components-front 3.6.1: setting mode = 'edge' on a disabled LengthMeasurement makes the snap marker of GraphicVertexPicker visible, and it then follows the cursor although the tool is off.

Expected

A disabled measurer never shows the snap marker. Changing its configuration (mode, units, snappings) while it is disabled has no visible effect.

Cause

  • The LengthMeasurement.mode setter calls initPreview() for 'edge' without checking enabled.
  • buildPreview() calls this._vertexPicker.get() when lastPick is null, before it checks this.enabled.
  • GraphicVertexPicker.get() never checks _enabled and sets marker.visible = true on every hit.
  • Cursor tracking (attachCursorTracking) stays attached as long as a world is set, so the marker then keeps following the cursor.

The same pattern can be hit by any other pick that resolves while the measurer is disabled, e.g. a pending scheduleMarkerUpdate() pick (it checks this.enabled only before awaiting) or the unawaited get() in the GraphicVertexPicker.enabled setter.

Suggested fix

  • In GraphicVertexPicker.get(), after the await, only touch the marker if the picker is enabled: if (!this._enabled) { if (this.marker) this.marker.visible = false; return n; }.
  • In LengthMeasurement, only call initPreview() from the mode setter when this.enabled is true.

Versions

  • @thatopen/components 3.6.0
  • @thatopen/components-front 3.6.1
  • @thatopen/fragments 3.6.1
  • three 0.182.0

Reproduction ▶️

https://stackblitz.com/github/berchri/thatopen-snap-marker-repro; https://github.com/berchri/thatopen-snap-marker-repro
Open in StackBlitz

Steps to reproduce 🔢

  1. Wait for the model to load. The measurer is configured with a world, mode = 'free', and stays disabled (enabled = false).
  2. Click once into the viewer so it has keyboard focus (on StackBlitz the preview needs focus), hover over the model and press M. M toggles measurer.mode between 'free' and 'edge'; the current mode is shown in the panel.
  3. Move the mouse. The snap marker is visible and follows the cursor although the measurer is disabled. The console logs BUG: measurer disabled, but snap marker is visible every second.

Pressing E toggles measurer.enabled for comparison; enabling and disabling the tool alone behaves correctly.

image

System Info 💻

OS: Windows 11 10.0.26100
Node: 24.20.0, npm: 11.19.0
Browsers: Chrome 158.0.8127.37, Edge 158.0.4370.45
@thatopen/components 3.6.0, @thatopen/components-front 3.6.1,
@thatopen/fragments 3.6.1, three 0.182.0, web-ifc 0.0.77

Used Package Manager 📦

npm

Error Trace/Logs 📃

No response

Validations ✅

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.

Activity

  1. added
    bug
    on Nov 27, 2026
  2. berchri commented on Nov 27, 2026

    @berchri
    Author

    Suggested fix in packages/front/src/measurement/LengthMeasurement/index.ts:

       set mode(value: LengthMeasurerModes[number]) {
         this._mode = value;
         this.cancelCreation();
    -    if (value === "edge") this.initPreview();
    +    // onEnabledChange starts the edge preview once the tool is enabled.
    +    if (value === "edge" && this.enabled) this.initPreview();
         this.onStateChanged.trigger(["mode"]);
       }

    Optionally, as a second guard, buildPreview() could return early before picking:

       private async buildPreview() {
         if (!this.world) {
           throw new Error("Measurement: world is need!");
         }
    +    if (!this.enabled) return;

    Nothing is lost when the mode is set while disabled: onEnabledChange already calls initPreview() for edge when the tool gets enabled.

    Happy to open a PR with this change if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions