Skip to content

Conversation

@ryo-fujinone
Copy link

@ryo-fujinone ryo-fujinone commented Jun 1, 2025

  • moved dispatch of loadstart event to send()
  • included ProgressEvent-specific properties in loadstart/load/loadend

moved dispatch of loadstart event to send()

Native XHR fires the loadstart event right after xhr.send(), so xhr.addEventListener(“loadstart”, listener) can be placed either before or after xhr.open().
xhook currently dispatches loadstart inside open(). If xhr.open() is called before xhr.addEventListener(“loadstart”, listener), that listener will not work.
This issue is fixed by moving the loadstart dispatch to send().

I noticed an interesting comment just before the loadstart dispatch, but personally, I think we should imitate the behavior of native XHR.

// make fake events for libraries that actually check the type on
// the event object

included ProgressEvent-specific properties in loadstart/load/loadend

In native XHR, the loadstart/load/loadend events are ProgressEvent and have specific properties (lengthComputable, loaded, total).
These were missing from the xhook events, so I added them.

  • loadstart
    • sets initial values.
  • progress
    • caches the latest { lengthComputable, loaded, total } in a private variable (lastProgress).
  • load/loadend
    • uses the cached values when available.

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.

1 participant