Skip to content

Ensure request is defined in error handler - #38

Draft
YarnSaw wants to merge 2 commits into
mjwwit:masterfrom
YarnSaw:abort-sets-request-null
Draft

YarnSaw wants to merge 2 commits into
mjwwit:masterfrom
YarnSaw:abort-sets-request-null

Conversation

@YarnSaw

@YarnSaw YarnSaw commented Oct 26, 2026

Copy link
Copy Markdown

Addresses #37.

Used request && rather than optional chaining since I vaguely recall backwards compatibility being important, and optional chaining was only introduced in node 14.

@mjwwit mjwwit left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for finding this and spending time on creating the fix.

However, this only prevents the null dereference, but the error handler still processes errors from aborted requests. If the same XHR is reopened and sent before the old request emits its error, request points to the new request, so the null check passes and the old error can corrupt the new request’s state or trigger an incorrect retry.

Could we associate the handler with its originating request and ignore errors from aborted or superseded requests before retrying or calling handleError? Please add regression coverage for aborting a pending request and immediately reusing the same XHR.

@YarnSaw
YarnSaw marked this pull request as draft October 29, 2026 20:46
@YarnSaw

YarnSaw commented Oct 29, 2026

Copy link
Copy Markdown
Author

I see I broke node 13 compatibility on my new regression test, I'll fix that.

Also not 100% happy with my most recent commit, realized after that if a new xhr.open is called after the abort it'll still break. I'll undraft the PR once that's fixed.

@mjwwit

mjwwit commented Nov 2, 2026

Copy link
Copy Markdown
Owner

I'm quite far into a full refactor of the entire project and that will definitely fix this problem. It will be released as a major version, so I'd not spend too much time on this unless you'd like me to release it as a patch on the current major.

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