rails-profiler 0.44.33 → 0.44.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@
22
22
  const originalXHROpen = XMLHttpRequest.prototype.open;
23
23
  const originalXHRSend = XMLHttpRequest.prototype.send;
24
24
  const pendingXHRRequests = new WeakMap();
25
+ const xhrLoadListeners = new WeakMap();
25
26
  // The fetches Turbo makes, by the AbortSignal it hands to fetch(): { frame: true } when the
26
27
  // request loads a <turbo-frame>.
27
28
  const turboRequests = new WeakMap();
@@ -175,7 +176,7 @@
175
176
 
176
177
  // Override XMLHttpRequest.open()
177
178
  XMLHttpRequest.prototype.open = function(method, url, ...args) {
178
- const urlString = typeof url === 'string' ? url : url.toString();
179
+ const urlString = typeof url === 'string' ? url : String(url);
179
180
 
180
181
  // Store request metadata
181
182
  pendingXHRRequests.set(this, {
@@ -196,14 +197,22 @@
196
197
  return originalXHRSend.apply(this, args);
197
198
  }
198
199
 
200
+ // Remove any previous load listener to avoid duplicates on reused XHR instances
201
+ const previousListener = xhrLoadListeners.get(this);
202
+ if (previousListener) {
203
+ this.removeEventListener('load', previousListener);
204
+ }
205
+
199
206
  // Add load event listener to capture response
200
- this.addEventListener('load', function() {
207
+ const handleLoad = function() {
201
208
  const profilerToken = this.getResponseHeader('X-Profiler-Token');
202
209
 
203
210
  if (profilerToken && requestData) {
204
211
  linkChildProfile(profilerToken);
205
212
  }
206
- });
213
+ };
214
+ this.addEventListener('load', handleLoad);
215
+ xhrLoadListeners.set(this, handleLoad);
207
216
 
208
217
  return originalXHRSend.apply(this, args);
209
218
  };
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Profiler
4
- VERSION = "0.44.33"
4
+ VERSION = "0.44.34"
5
5
 
6
6
  GEM_ROOT = File.expand_path("../..", __dir__)
7
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.33
4
+ version: 0.44.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Duplessy