microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.4k stars 1.14k forks source link

XMLHttpRequest readyState 4 does not guarantee full response data #13408

Open capagrisdesu opened 5 months ago

capagrisdesu commented 5 months ago

Problem Description

This merge may be problematic for many public libraries out there and new devs in React Native Windows that come from any other platform that uses XMLHttpRequest. https://github.com/microsoft/react-native-windows/pull/10933

For example, I am using hls.js which uses on onreadystatechange which sets incremental steps to true. There is no documentation about what this is about and how to switch it off or how to handle incremental responses... This causes the library to fail because when readyState is 4, then will use the response to play content which is capped to 128kb.

I searched but I could not find any documentation and samples about incremental steps.

Steps To Reproduce

Any XMLHttpRequest request using onreadystatechange downloading a file greater than 128kb.

Expected Results

Incremental updates should be a featured that is disabled by default, not something enabled by design there because for most devs from any platform using XMLHttpRequest will be unaware of such behavior.

There should be documentation that states how incremental updates work and samples about how to use it along with onreadystatechange.

CLI version

13.6.6

Environment

System:
  OS: Windows 10 10.0.19045
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12800H
  Memory: 15.35 GB / 31.68 GB
Binaries:
  Node:
    version: 22.3.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 3.6.4
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 10.8.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    Android NDK: 23.2.8568313
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.22621.0
IDEs:
  Android Studio: AI-221.6008.13.2211.9477386
  Visual Studio:
    - 17.10.35004.147 (Visual Studio Community 2022)
    - 16.11.34931.43 (Visual Studio Professional 2019)
Languages:
  Java:
    version: 11.0.15
    path: /c/Program Files/Android/Android Studio/jbr/bin/javac
  Ruby:
    version: 3.1.3
    path: C:\Ruby31-x64\bin\ruby.EXE
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-windows:
    installed: 0.74.7
    wanted: 0.74.7
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

info React Native v0.74.3 is now available (your project is running on v0.74.2).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.74.3
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.2
info For more info, check out "https://reactnative.dev/docs/upgrading?os=windows".

Community Modules

No response

Target Platform Version

None

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2022

Build Configuration

None

Snack, code example, screenshot, or link to a repository

No response

JunielKatarn commented 4 months ago

@capagrisdesu To clarify, is this not the behavior on other React Native platforms (iOS, Android...)?

At a first glance, this seems to happen by design for any React Native platform. See https://github.com/facebook/react-native/blob/v0.74.3/packages/react-native/Libraries/Network/XMLHttpRequest.js#L523

capagrisdesu commented 4 months ago

I think that is not what I would call a good question since that seems to be focused on other platforms. A good question to me is more like... If that is the design of the XMLHttpRequest how do files greater than 128kb are downloaded incrementally in RN Windows? You are the one to answer that and provide samples about how is done or maybe this requires a fix because if you were to look at the Web API standards of XMLHttpRequest you can see that readyState 4 guarantees that the full file is delivered.

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState

So the question that your team should think about is how you get a file larger than 128kb using XMLHttpRequest and having defined a onreadystatechange function to the request.

capagrisdesu commented 4 months ago

I guess that also I could say that I do not know the answer to your question. But his issue attempts to shed light on how this incremental is supposed to comply with the Web API standards of XMLHttpRequest and readyState 4. So I would hope that you do know the answer for it and explain what may be obvious to you.

JunielKatarn commented 4 months ago

I guess that also I could say that I do not know the answer to your question. But his issue attempts to shed light on how this incremental is supposed to comply with the Web API standards of XMLHttpRequest and readyState 4. So I would hope that you do know the answer for it and explain what may be obvious to you.

Not being involved in React Native for non-Windows platforms, I also do not know the answer. If this the by-design React Native behavior, then this issue is best to bring up with the Meta team and the upstream repository.