Title: fix(zone.js): preserve accessor and non-enumerable event listener options by stefanwaldhauser · Pull Request #70432 · angular/angular · GitHub
Open Graph Title: fix(zone.js): preserve accessor and non-enumerable event listener options by stefanwaldhauser · Pull Request #70432 · angular/angular
X Title: fix(zone.js): preserve accessor and non-enumerable event listener options by stefanwaldhauser · Pull Request #70432 · angular/angular
Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md Tests for the changes have been added (for bug fixes / features) PR Type Bugfix What is the current behavior? Issue Number: #70431 Since zone.js 0.14.7 (June 2024, #55796), the patched addEventListener silently drops event listener options that are exposed as accessors or as non-enumerable properties. copyEventListenerOptions copies the caller's options with {...options} before forwarding to native. Object spread copies only own enumerable data properties. The native call, by contrast, reads each dictionary member via WebIDL — a plain [[Get]], which invokes accessors and ignores enumerability. The copy is therefore lossy in a way the native call is not. Observed in Chromium, zone.js 0.15.1: option supplied as an accessor without zone.js with zone.js capture: true capturing phase (1) bubbling phase (3) once: true fires once fires every time passive getter (feature-detection) getter invoked never invoked Nothing throws in any case. signal was already special-cased for AbortController.prototype.signal after #54142; the other three members were not. The passive row is the one with ecosystem-wide fallout: it defeats the MDN feature test for passive-listener support, where the getter being read is the signal. That snippet is used verbatim by Highcharts (See: https://github.com/highcharts/highcharts/blob/69edf8952a04b9872b6510fbdacd7dff8b03970b/ts/Core/Globals.ts#L201). Making every listener they register non-passive. Including ones they explicitly intended to be passive. What is the new behavior? The copy is still made — that fix from #55796 is preserved (frozen/readonly options still work). Each recognised member (capture, once, passive, signal) is additionally read from the source object via [[Get]] when the spread didn't already produce it, which recovers non-enumerable and prototype accessors. The hasOwnProperty gate on the loop ensures no getter is invoked twice. The call site is reordered to buildEventListenerOptions(copyEventListenerOptions(...)) so the passive-events code path ({...options, passive: true} in buildEventListenerOptions) also spreads a normalised data object rather than the caller's raw input. Tests added in packages/zone.js/test/browser/browser.spec.ts cover: non-enumerable passive getter invoked exactly once (MDN feature-detect pattern); capture: true accessor honoured for both add and remove; once: true accessor honoured across two dispatches; AbortController passed directly as options (regression guard for #54142); frozen options object accepted without mutation (regression guard for #55796). Alternatives considered and rejected: Spread, then unconditionally re-read the four members. Double-invokes enumerable accessors. Descriptor-preserving copy (Object.defineProperties({}, Object.getOwnPropertyDescriptors(options))). Loses signal — it lives on AbortController.prototype, not as an own property. Prototype-preserving copy (Object.create(Object.getPrototypeOf(options), Object.getOwnPropertyDescriptors(options))). Throws on built-ins: TypeError: Cannot read private member #signal from an object whose class did not declare it. This is the hazard the pre-existing code comment already warned about. Does this PR introduce a breaking change? Yes No Other information Provenance: introduced by #55796 / 85c1719. Bisected: 0.13.3, 0.14.0, 0.14.4, 0.14.6 all behave correctly; 0.14.7 → 0.16.2 do not. Fixes #70431.
Open Graph Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md Tests for the changes have been added (for bug...
X Description: PR Checklist The commit message follows our guidelines: https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md Tests for the changes have been added (for bug...
Opengraph URL: https://github.com/angular/angular/pull/70432
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:3f07bac2-57f3-2d2b-8a1e-0ec912e30647 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9E18:11284C:2055B:2AD64:6B015AEC |
| html-safe-nonce | 0164fae8312a6f229d831d15dbe10713285519f95f036915ba4aaaada31b560b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTE4OjExMjg0QzoyMDU1QjoyQUQ2NDo2QjAxNUFFQyIsInZpc2l0b3JfaWQiOiI1Njg5ODAyMjY4NDEzNjE0ODI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 107812be8f4c0157233d41615c923096a02698f007a8176d218928f169514876 |
| hovercard-subject-tag | pull_request:4376527462 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular/pull/70432/files |
| twitter:image | https://avatars.githubusercontent.com/u/29718932?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/29718932?s=400&v=4 |
| og:image:alt | PR Checklist The commit message follows our guidelines: https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md Tests for the changes have been added (for bug... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width