Skip to content

Browser-floor cleanup: drop legacy polyfills + modernise wheel/scroll#153

Draft
moodyjmz wants to merge 4 commits into
mainfrom
fix/browser-floor-stage1
Draft

Browser-floor cleanup: drop legacy polyfills + modernise wheel/scroll#153
moodyjmz wants to merge 4 commits into
mainfrom
fix/browser-floor-stage1

Conversation

@moodyjmz

@moodyjmz moodyjmz commented Jun 30, 2026

Copy link
Copy Markdown
Member

Low-hanging-fruit browser-floor cleanup — removes dead weight, no behavioural risk on the modern floor.

  • 🔥 Stop deploying fetch / es6-promise polyfills (unused once IE/legacy is off the floor).
  • 🐛 Replace DOMMouseScroll / mousewheel UA-sniffing with the standard wheel event across desktop editors.
Details

Polyfillsfetch and es6-promise are dropped from build/vendor.manifest.mjs, so the deploy step stops copying them. The vendor dirs stay in the tree (upstream keeps shipping them); we just don't deploy them.

Wheel/scroll — three fixes in the desktop editors' Print.js / DocumentHolder.js:

  1. Replace the DOMMouseScroll/mousewheel UA-sniff with the standard wheel event.
  2. Switch Print.js binding from jQuery .on() to addEventListener.
  3. Correct the wheel delta sign in Print.js and DocumentHolder.js.

Part of the browser-floor-stage1 work; the mobile/ES2022 half is a separate PR.

moodyjmz and others added 2 commits June 30, 2026 09:55
Both polyfills are unreachable in any supported browser — native fetch/Promise
are universal since Chrome 42/FF 39/Safari 10.1. The codebase already calls
fetch() unconditionally at multiple sites regardless of the locale.js guard.

The locale.js guard was already stripped at build time by the locale-fetch
string-replace-loader rule (webpack.editor.factory.mjs:161). vendor/fetch/
and vendor/es6-promise/ stay in-tree so upstream pulls stay clean; they are
no longer copied to BUILD_ROOT.

Closes #129 (fetch/es6-promise portion).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
…event

DOMMouseScroll was removed in Firefox 87 (March 2021). The UA sniff routed all
Firefox users into registering a DOMMouseScroll listener — an event that is never
dispatched. Firefox scroll was silently broken in the document area of all editors.

Replace with the standard wheel event (universal since 2014) across all 11 affected
files. Two listener patterns updated:

- DocumentHolder.js × 5 editors + DocumentHolderExt.js: event name + collapse the
  isChrome/jQuery ternary to a single document.addEventListener('wheel', ..., {passive:false})
- Print.js × 5 editors: event name only
- TabBar.js: unify Mac/non-Mac binding (both now use wheel → _onMouseWheelThrottled);
  fix delta reading with deltaMode normalisation so Firefox line-unit deltas (deltaMode=1)
  are not swallowed by the magnitude threshold

vendor/perfect-scrollbar/src/jquery.mousewheel.js left alone (vendored upstream source).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
@moodyjmz moodyjmz requested a review from a team as a code owner June 30, 2026 07:59
@moodyjmz moodyjmz requested review from MonaAghili and emberfiend and removed request for a team June 30, 2026 07:59
@moodyjmz moodyjmz self-assigned this Jun 30, 2026

var eventname = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
var eventname = 'wheel';
this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

as far as I understand $previewBox is a jquery obj and in current version of it which is 3.5.1 the wheel event doesn't expose deltaY on the jquery event object which means e.deltaY would be undefined so forward wil lbe always false

would it make sense to change the event back to mousewheel in all printjs files? The jquery.mousewheel plugin can provide e.deltaY for mousewheel events

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch — you're right. jQuery 3 wraps events and doesn't copy deltaY into the wrapper, so e.deltaY was undefined and forward always evaluated to false.

Fixed in 230a052: switched all five Print.js files from $previewBox.on('wheel', ...) to native $previewBox[0].addEventListener('wheel', ..., {passive: false}). The {passive: false} is needed because onPreviewWheel calls preventDefault() on Ctrl+scroll — consistent with how DocumentHolder.js already binds its wheel listener.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair point, and you were right about the version you saw — jQuery wasn't exposing deltaY on the wheel event. Since switched to native addEventListener('wheel', …) which does. Apologies for the drive-by review request though — Claude got a bit eager and pinged reviewers when this should've gone up as a draft first. Marking it draft now while I finish the runtime testing. :P

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@moodyjmz
No need to apologize!!! we're a team and the whole point of reviews is to catch things together and make the project better
It happens to every single of us especially in a big codebase even claude misses things sometimes!

other than that I didn't find any other issues and LGTM!

…EventListener

jQuery 3 wraps events and does not copy deltaY to the wrapper object, so
$el.on('wheel', handler) produces e.deltaY === undefined — forward always false.

Switch to native addEventListener (consistent with DocumentHolder.js) so the
handler receives a real WheelEvent. Pass {passive: false} since onPreviewWheel
calls preventDefault() on Ctrl+scroll.

Caught by MonaAghili in PR review.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
@moodyjmz moodyjmz marked this pull request as draft June 30, 2026 09:39
@moodyjmz moodyjmz removed the request for review from emberfiend June 30, 2026 09:39
…heel handlers

The old jQuery .on('mousewheel') path routed through the jquery.mousewheel plugin
(vendor/perfect-scrollbar/src/jquery.mousewheel.js) which negates native deltaY to
up-positive (scroll up = positive). Native wheel event is down-positive. TabBar.js
already accounts for this. The other two handler families did not.

Print.js (×5): forward = (e.deltaY||...) < 0 → scroll down gave deltaY>0, forward=false,
onChangePreviewPage(false) → previous page. Inverted on all browsers, including Chrome
(regression from this PR). Fix: forward = e.deltaY > 0.

DocumentHolder.js (×5): delta reading fell through to event.deltaY when wheelDelta was
absent (Firefox), giving down-positive delta → Ctrl+scroll up → zoomOut. Inverted on
Firefox. Fix: negate deltaY (-event.deltaY) to match the up-positive convention the
existing delta<0/delta>0 zoom branches expect.

Caught by independent code review.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
@moodyjmz

Copy link
Copy Markdown
Member Author

Independent review caught two sign-inversion bugs introduced by this PR — both now fixed in 0ffa044.


Root cause

The old jQuery .on('mousewheel', handler) path routed through vendor/perfect-scrollbar/src/jquery.mousewheel.js, which negates native deltaY to up-positive (scroll up = positive, matching legacy wheelDelta). Switching to native addEventListener('wheel') bypasses that plugin entirely. TabBar.js._onMouseWheelThrottled was already written to account for this (-deltaY). The other two handler families were not.

Bug 1 — Print preview scroll direction inverted (all browsers)

onPreviewWheel in all five Print.js files:

// before: down-scroll → deltaY > 0 → forward = false → previous page (wrong)
var forward = (e.deltaY || ...) < 0;
// after
var forward = e.deltaY > 0;

This regressed Chrome, which worked before the PR.

Bug 2 — Ctrl+scroll zoom direction inverted (Firefox)

handleDocumentWheel / onDocumentWheel in all five editors:

// before: Firefox has no wheelDelta → fell through to raw deltaY → down-positive
//         scroll up → deltaY < 0 → delta < 0 → zoomOut (wrong)
var delta = (_.isUndefined(event.originalEvent)) ? event.wheelDelta : event.originalEvent.wheelDelta;
if (_.isUndefined(delta)) { delta = event.deltaY; }

// after: negate deltaY → up-positive → existing delta>0=zoomIn stays correct
var delta = event.deltaY !== undefined ? -event.deltaY : event.wheelDelta;

Firefox had no working Ctrl+zoom before this PR (DOMMouseScroll path was dead). The fix makes it correct rather than merely swapping dead for inverted.

@moodyjmz moodyjmz changed the title fix(scroll): replace DOMMouseScroll UA sniff with wheel event; drop fetch/es6-promise polyfills Browser floor stage 1: ES2022 mobile target + i18next crash fix, mobile deploy (#258), scroll/polyfill modernisation Jun 30, 2026
@moodyjmz moodyjmz force-pushed the fix/browser-floor-stage1 branch from 696e515 to 0ffa044 Compare June 30, 2026 18:12
@moodyjmz moodyjmz changed the title Browser floor stage 1: ES2022 mobile target + i18next crash fix, mobile deploy (#258), scroll/polyfill modernisation Browser-floor cleanup: drop legacy polyfills + modernise wheel/scroll Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants