Repository navigation
fix: remove xhr loadend listener after each request - #295
Open
velocitysystems wants to merge 1 commit into
Open
velocitysystems wants to merge 1 commit into
velocitysystems wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the non-blocking review comment on #269 (thread).
Problem
Each intercepted
send()added an anonymousloadendlistener and never removed it. In React Native,abort()resets an XMLHttpRequest toUNSENT, so it can be opened and sent again. A reused request kept one listener for every earlier send, and each completion calledonResponsefor all of them: N reuses made N(N+1)/2 calls. The RUMWeakMapignored the extra calls, so no duplicate events were sent, but the work grew with each reuse.Normal requests are not affected. After a request completes without
abort(),open()throws, and libraries such as axios create a new XMLHttpRequest for each request.Fix
The
loadendlistener now removes itself when it runs.The fix does not use
{ once: true }. In React Native 0.81 to 0.87,XMLHttpRequest.addEventListener(type, listener)passes only those two arguments toEventTarget, so the option would be ignored on devices but would pass in Jest.Tests
onResponseto be called 3 times. Without the fix, it is called 6 times.removeEventListenerto the fake XMLHttpRequest inNetworkInterceptor.test.tsandRealUserMonitor.test.ts.Verification
npm test: 43 pass.tsc --noEmitpasses fortsconfig.jsonandtsconfig.test.json. ESLint and Prettier pass.