Skip to content

An abandoned live brush loses a response that landed during the brush #92

Open

Description

@jvdd

Problem

A live-brush preview writes cube data to its target layers with a new write number (fvNextWriteSeq, runtime/delta.js). A response that lands during the brush carries an older number, so the target layers refuse it. When the brush is abandoned, _fvCubeGestureAbort (plotly/events.js) puts back the data from before the drag, together with its number. The refused response is not recovered.

Result: the target shows old data under its current viewport. No request is pending that can correct it, so it stays wrong until a later interaction re-aggregates that figure.

This is not new. main gives the same result: there, the response overwrote the preview, and the abort then put back the data from before the drag. PR #89 fixes the other order: a response that lands after the abort now applies.

Reachability

Reproduced in a browser (test below). The case needs a pending response and an abort after live frames. The aborts are safety paths:

  • An edit drag of an existing box, when Plotly emits no plotly_selected within _FV_SELECTION_EDIT_ABORT_MS (1.5 s).
  • A deselect during the drag.
  • An empty plotly_selected. test_abandoned_gesture_restores_targets notes that headless Plotly 3 has no reliable mouse trigger for it, so the test emits it by hand.

The case is most likely on a slow source, where a zoom response is still pending when the user starts a brush.

Repro

Two-histogram cube dashboard, live_brush="auto":

  1. Zoom the target histogram to [20, 60]. Hold its response.
  2. Start a live brush on the source histogram. Wait until the target shows the preview.
  3. Release the zoom response. The target refuses it.
  4. Abandon the brush with an empty plotly_selected.

Expected: the target bins lie inside [20, 60] (the zoom response).
Actual: the full-range bins from before the drag (centers 4.2 to 95.6) under the [20, 60] axis.

Browser test for tests/test_browser_cube.py (uses the helpers from PR #89)
    def test_abandoned_gesture_keeps_a_response_that_landed_during_it(
        self, page: Page, server_port: int
    ):
        url = _two_hist_dashboard_url(server_port, "_cube_browser_abandon_during", "auto")
        page.goto(url)
        _wait_for_init(page, "plotly")
        page.evaluate(_COUNT_SETTLED_UPDATES)
        _enter_select_mode(page)
        held = _hold_first_update(page)
        page.evaluate("() => Plotly.relayout(divs[1], {'xaxis.range': [20, 60]})")
        _wait_held(page, held)

        y_before = _target_y(page)
        x1, x2, y, _width = _drag_coords(page)
        page.mouse.move(x1, y)
        page.mouse.down()
        page.mouse.move((x1 + x2) / 2, y, steps=8)
        page.wait_for_function(
            """(yBefore) => {
                const ys = Array.from(divs[1].data[0].y || []);
                return ys.length > 0 && JSON.stringify(ys) !== JSON.stringify(yBefore);
            }""",
            arg=y_before,
            timeout=10_000,
        )
        _release(page, held, settled=1)  # the preview holds the target: refused
        page.evaluate("divs[0].emit('plotly_selected', undefined)")
        page.wait_for_timeout(500)

        centers = page.eval_on_selector("#fv-plot-1", "gd => Array.from(gd.data[0].x)")
        assert 20 <= min(centers) and max(centers) <= 60, centers

It fails on the PR #89 branch with assert (20 <= 4.1583333333375).

Fix direction

Two options:

  1. Keep refused responses in the saved state. When a live preview refuses a response that is newer than the saved pre-drag data, _fvClaimSlot stores the response in the saved state. The abort then puts back the response. This is about 20 lines in delta.js, plus a registry of saved slots that a commit clears. It covers a request sent before the brush, which is the realistic order. A request sent during the brush is still lost: its response is accepted, and the abort then overwrites it.
  2. Keep previews out of the layer slots. Previews go to a separate preview layer that the renderer reads first. A commit copies the preview into the slots with a new number. An abort drops the preview. Server responses then always follow the normal order rule, and the save and restore code (fvSaveLayerData, fvSaveHasBackground) goes away. This is complete. It touches the cube live-brush path, the renderer reads in buildTracesForFigure, and the cube reads of recorded child results in runtime/cube.js.

Option 2 is preferred when the cube live-brush path next changes. The fix also removes the ponytail: note above fvSaveLayerData, which describes this limitation.

Related: #75, #89.

Activity

  1. added
    bug
    on Sep 25, 2026
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