Skip to content

Zoom event listeners are passed an incorrect sourceEvent if a programmatic zoom occurs during a user zoom gesture #253

Open
@yurivish

Description

Programmatic zoom intiated while the user is making a gesture causes the zoom callback to be invoked with the sourceEvent from the preceding user action, rather than an undefined sourceEvent.

I think this is because there is an active Gesture on the element and the following line does not update the event to null or undefined:

if (event) this.sourceEvent = event;

which is called indirectly from

https://github.com/d3/d3-zoom/blob/main/src/zoom.js#L85

with an undefined event.


Example: https://observablehq.com/d/11402b3301150892 (see console for stack overflow)

The example notebook tries to perform a programmatic zoom once for every user-initiated zoom, but because the programmatic zoomed callback is invoked with a trusted sourceEvent, this results in infinite recursion.

First noticed here (which now implements a workaround)

Activity

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

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