Skip to content

Patch event listeners for touch events to be non-passive, Fix scroll-blocking touch event listeners in OpenLayers legacy#6449

Merged
rldhont merged 1 commit into3liz:masterfrom
Antoviscomi:patch-9
Jan 27, 2026
Merged

Patch event listeners for touch events to be non-passive, Fix scroll-blocking touch event listeners in OpenLayers legacy#6449
rldhont merged 1 commit into3liz:masterfrom
Antoviscomi:patch-9

Conversation

@Antoviscomi
Copy link
Copy Markdown
Contributor

@Antoviscomi Antoviscomi commented Jan 26, 2026

Added a patch to modify event listener behavior for touch events, ensuring non-passive listeners are used to maintain map interaction fluidly.

This PR addresses the performance violations and laggy interactions on touch devices caused by non-passive event listeners in the legacy OpenLayers 2 components.

Chrome and other modern browsers flag these as [Violation] because they block the main thread while waiting for a potential preventDefault(). In a mapping context, this delay results in jerky zoom and pan movements.

Changes
Added a global EventTarget patch in index.js: This interceptor captures touchstart and touchmove events.

Explicitly set passive: false: While it sounds counter-intuitive, forcing passive: false tells the browser that we intend to use preventDefault() for map interactions, eliminating the 100-200ms "observation" delay the browser would otherwise impose.

Ensured compatibility: The patch handles both boolean and object-based addEventListener signatures, ensuring no breakage in legacy code or newer components.

Performance Impact
Interaction Latency: Reduced. Map panning and zooming on mobile/touch screens are now significantly smoother.

Console Violations: Mitigated the "Added non-passive event listener" warnings.

Load Time: During testing, the overall map initialization remains fast (approx. 640ms in dev environment).

Testing
Tested on Chrome 144.0.7559.96 with mobile emulation and physical touch devices.

Verified that map panning, zooming, and drawing tools (which require preventDefault) still function correctly.

Confirmed that Ctrl+Shift+R (hard refresh) is necessary to clear the legacy JS cache and apply the fix.

Added a patch to modify event listener behavior for touch events, ensuring non-passive listeners are used to maintain map interaction fluidly.
@github-actions github-actions Bot added this to the 3.11.0 milestone Jan 26, 2026
Copy link
Copy Markdown
Collaborator

@mdouchin mdouchin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

Comment thread assets/src/index.js
@Antoviscomi Antoviscomi requested a review from nworr January 26, 2026 17:09
@nboisteault
Copy link
Copy Markdown
Member

@Antoviscomi OL2 map is only used for edition. Can you confirm that you watched lags only in edition mode?

@Antoviscomi
Copy link
Copy Markdown
Contributor Author

Antoviscomi commented Jan 27, 2026

@Antoviscomi OL2 map is only used for edition. Can you confirm that you watched lags only in edition mode?

Yes, @nboisteault , I can confirm that.
While the lags were significantly more pronounced during edition tasks (where interaction is more intense), I consistently observed the [Violation] Added non-passive event listener to a scroll-blocking touchstart event warnings right at the initial map load, even before entering edition mode. As in classic browser view as in Touch emulation view mode by Chrome dev console

It appears that the OpenLayers 2 legacy core registers these listeners globally upon initialization. By patching these to be non-passive, I've seen two major benefits:

At Startup: The browser console is now clean of violation warnings, and the main thread is no longer throttled during the initial rendering.

In Edition: The interaction is finally fluid, as the browser doesn't have to wait for the scroll-blocking check on every touch event.

Furthermore, without the patch, those violations would multiply exponentially during editing. Since every map pan or vertex drag triggers continuous redraws and event processing, the scroll-blocking nature of the original listeners caused a massive overhead. Now, even with heavy interaction, the thread stays free and the 'incalculable' violations I previously saw are completely gone

In my current environment (running via Rspack/Apache), the load time is now a solid 670ms and the map feels much more responsive overall.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants