Skip to content

fix: WebSocket binaryType handling — stop unconditional Blob interception of binary messages#16173

Open
gmacmaster wants to merge 8 commits into
microsoft:mainfrom
Virtual-Fulfillment-Technologies-Inc:vendora/fix-websockets
Open

fix: WebSocket binaryType handling — stop unconditional Blob interception of binary messages#16173
gmacmaster wants to merge 8 commits into
microsoft:mainfrom
Virtual-Fulfillment-Technologies-Inc:vendora/fix-websockets

Conversation

@gmacmaster
Copy link
Copy Markdown
Contributor

@gmacmaster gmacmaster commented May 22, 2026

Description

WebSocket binaryType = 'arraybuffer' is silently broken on React Native Windows.

Type of Change

Bug fix (non-breaking change which fixes an issue)

Why

WebSocket binaryType = 'arraybuffer' is silently broken on React Native Windows. All binary WebSocket messages are unconditionally intercepted by BlobWebSocketModuleContentHandler and converted to Blobs, regardless of whether the socket has been registered for blob handling via addWebSocketHandler. This means:

Setting binaryType = 'arraybuffer' has no effect — binary messages still arrive as Blobs
The JavaScript-side WebSocket.js never executes its base64-to-ArrayBuffer conversion path for binary messages
Applications relying on ArrayBuffer delivery (e.g., PowerSync, binary protocol clients) are forced to implement custom Blob-to-ArrayBuffer conversion patches
This diverges from the behavior on iOS and Android, where binaryType correctly controls binary message delivery format.

What

The root cause is in DefaultBlobResource.cpp: IBlobResource::Make() unconditionally registers a BlobWebSocketModuleContentHandler on the ReactContext property bag, and WebSocketModule.cpp routes all binary messages through it without checking whether the specific socket was registered via addWebSocketHandler.

The BlobWebSocketModuleContentHandler already tracks registered socket IDs in m_socketIds (populated by Register/Unregister), but this set was never consulted during message processing.

Changes across 4 files:

IWebSocketModuleContentHandler.h — Changed both ProcessMessage overloads from void to bool return type. true = message was handled by the content handler; false = caller should fall back to default delivery.

DefaultBlobResource.h — Updated BlobWebSocketModuleContentHandler::ProcessMessage signatures to return bool.

DefaultBlobResource.cpp — Both ProcessMessage overloads now read the socket ID from params["id"], acquire m_mutex, and check m_socketIds. If the socket is not registered, they return false without processing. This check is atomic with the message processing, avoiding any TOCTOU gap between a separate Supports() check and ProcessMessage.

WebSocketModule.cpp — The SetOnMessage callback now checks the bool return value from ProcessMessage. If false, it falls through to the default path (args["data"] = message), which delivers the base64-encoded binary data to JavaScript where WebSocket.js decodes it to an ArrayBuffer.

Behavior after the fix:

binaryType = 'blob' (socket registered via addWebSocketHandler) — binary messages delivered as Blobs, same as before.
binaryType = 'arraybuffer' or default (socket not registered) — binary messages delivered as ArrayBuffer via the standard JS-side base64 decode path.
Screenshots
N/A — this is a data-path fix with no UI changes. Verified by observing WebSocket message delivery type in application-level diagnostics.

Testing

Verified end-to-end on a Windows device running a React Native application with PowerSync (real-time sync over binary WebSocket):

Before fix: All binary messages hit Blob conversion path (fileReader branch in application diagnostic stats), binaryType = 'arraybuffer' caused silent message drops.
After fix: All binary messages hit the passthrough/ArrayBuffer path (passthrough branch active, fileReader: 0), no message drops.
Tested both binaryType modes:

'arraybuffer' — messages arrive as ArrayBuffer in MessageEvent.data (was broken, now works)
'blob' — messages arrive as Blob in MessageEvent.data (still works, no regression)

Changelog

Should this change be included in the release notes: yes

Fix WebSocket binaryType handling on Windows — binary messages are no longer unconditionally converted to Blobs. Sockets using binaryType = 'arraybuffer' (the standard default) now correctly receive ArrayBuffer data.

Microsoft Reviewers: Open in CodeFlow

gmacmaster and others added 2 commits May 21, 2026 17:12
* blob support

* pr comments

* pr comments

* Update DefaultBlobResource.cpp
@gmacmaster gmacmaster requested review from a team as code owners May 22, 2026 00:29
@JunielKatarn
Copy link
Copy Markdown
Contributor

@microsoft/jshost allow me to review before approving.

@gmacmaster
Copy link
Copy Markdown
Contributor Author

@JunielKatarn have you had a chance to review?

@JunielKatarn
Copy link
Copy Markdown
Contributor

Beginning review.

@JunielKatarn
Copy link
Copy Markdown
Contributor

I have submitted a PR to your branch adding a test for this use case which will eventually be part of our automation.
Virtual-Fulfillment-Technologies-Inc#9
Feel free to adapt or improve if it doesn't properly test your change.

The change looks correct.
I only have feedback on where part of the implementation takes place and perhaps some naming convention.
I will add those specifics directly on the files section.

Comment thread vnext/Shared/Modules/IWebSocketModuleContentHandler.h Outdated
Comment thread vnext/Shared/Modules/IWebSocketModuleContentHandler.h Outdated
Comment thread vnext/Shared/Modules/WebSocketModule.cpp
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label May 31, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Jun 1, 2026
* Add WebSocketArrayBuffer headless test

* Skip test by default
@gmacmaster gmacmaster requested a review from a team as a code owner June 1, 2026 03:00
@gmacmaster
Copy link
Copy Markdown
Contributor Author

@JunielKatarn Comments addressed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Performance Test Results

Branch: vendora/fix-websockets
Commit: b736258b
Time: 2026-06-02T02:36:27.688Z
Tests: 161/161 passed

✅ Passed

161 scenario(s) across 28 suite(s) — no regressions

SectionList

Scenario Mean Median StdDev Renders vs Baseline
SectionList mount 3.20ms 3.00ms ±0.79ms 1 -40.0%
SectionList unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
SectionList rerender 6.90ms 7.00ms ±0.99ms 2 -33.3%
SectionList with-3-sections-15-items 3.70ms 3.00ms ±1.06ms 1 -45.5%
SectionList with-5-sections-50-items 3.80ms 4.00ms ±1.03ms 1 -33.3%
SectionList with-10-sections-200-items 3.90ms 4.00ms ±0.99ms 1 -27.3%
SectionList with-20-sections-200-items 3.20ms 3.00ms ±1.32ms 1 -40.0%
SectionList with-section-separator 1.70ms 1.00ms ±1.25ms 1 -50.0%
SectionList with-item-separator 1.10ms 1.00ms ±0.32ms 1 -50.0%
SectionList with-header-footer 1.40ms 1.00ms ±0.52ms 1 -50.0%
SectionList with-section-footer 1.20ms 1.00ms ±0.42ms 1 -50.0%
SectionList with-sticky-section-headers 1.00ms 1.00ms ±0.00ms 1 -50.0%
SectionList with-empty-list 0.30ms 0.00ms ±0.48ms 1 -100.0%
SectionList with-50-sections-1000-items 1.50ms 1.00ms ±0.97ms 1 -50.0%

FlatList

Scenario Mean Median StdDev Renders vs Baseline
FlatList mount 3.00ms 3.00ms ±0.47ms 1 -25.0%
FlatList unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
FlatList rerender 6.50ms 7.00ms ±0.71ms 2 -22.2%
FlatList with-10-items 2.90ms 3.00ms ±0.32ms 1 -25.0%
FlatList with-100-items 3.30ms 3.00ms ±1.42ms 1 -40.0%
FlatList with-500-items 3.50ms 3.00ms ±1.27ms 1 -25.0%
FlatList with-1000-items 3.10ms 3.00ms ±0.32ms 1 -25.0%
FlatList horizontal 3.10ms 3.00ms ±1.20ms 1 -40.0%
FlatList with-separator 1.00ms 1.00ms ±0.00ms 1 -50.0%
FlatList with-header-footer 1.10ms 1.00ms ±0.32ms 1 -50.0%
FlatList with-empty-list 0.40ms 0.00ms ±0.52ms 1 -100.0%
FlatList with-get-item-layout 1.10ms 1.00ms ±0.32ms 1 +0.0%
FlatList inverted 1.10ms 1.00ms ±0.32ms 1 -33.3%
FlatList with-num-columns 2.50ms 2.00ms ±1.58ms 1 -33.3%

TouchableOpacity

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity mount 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
TouchableOpacity rerender 0.90ms 1.00ms ±0.32ms 2 +0.0%
TouchableOpacity custom-active-opacity 0.40ms 0.00ms ±0.52ms 1 -100.0%
TouchableOpacity disabled 0.30ms 0.00ms ±0.48ms 1 -100.0%
TouchableOpacity with-all-handlers 0.40ms 0.00ms ±0.52ms 1 -100.0%
TouchableOpacity with-hit-slop 0.70ms 1.00ms ±0.48ms 1 +0.0%
TouchableOpacity with-delay 0.60ms 1.00ms ±0.52ms 1 +0.0%
TouchableOpacity nested 1.30ms 1.00ms ±0.95ms 1 +0.0%
TouchableOpacity multiple-10 3.80ms 3.00ms ±1.42ms 1 -50.0%
TouchableOpacity multiple-50 16.87ms 16.00ms ±1.81ms 1 -44.8%
TouchableOpacity multiple-100 14.80ms 15.00ms ±2.21ms 1 -70.0%

ScrollView

Scenario Mean Median StdDev Renders vs Baseline
ScrollView mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
ScrollView unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
ScrollView rerender 0.60ms 1.00ms ±0.52ms 2 +0.0%
ScrollView children-20 2.13ms 2.00ms ±0.52ms 1 -50.0%
ScrollView children-100 11.27ms 11.00ms ±1.49ms 1 -31.3%
ScrollView horizontal 2.30ms 2.00ms ±0.67ms 1 -50.0%
ScrollView sticky-headers 2.30ms 2.00ms ±1.25ms 1 -33.3%
ScrollView scroll-indicators 0.50ms 0.50ms ±0.53ms 1 -50.0%
ScrollView nested 1.10ms 1.00ms ±0.32ms 1 +0.0%
ScrollView content-container-style 0.50ms 0.50ms ±0.53ms 1 -50.0%
ScrollView children-500 16.27ms 15.00ms ±2.34ms 1 -21.1%

TouchableHighlight

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight mount 0.40ms 0.00ms ±0.52ms 1 -100.0%
TouchableHighlight unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
TouchableHighlight rerender 0.40ms 0.00ms ±0.52ms 2 -100.0%
TouchableHighlight custom-underlay-color 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight custom-active-opacity 0.20ms 0.00ms ±0.42ms 1 +0.0%
TouchableHighlight disabled 0.20ms 0.00ms ±0.42ms 1 +0.0%
TouchableHighlight with-all-handlers 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight with-hit-slop 0.30ms 0.00ms ±0.48ms 1 +0.0%
TouchableHighlight nested-touchables 0.50ms 0.50ms ±0.53ms 1 -50.0%
TouchableHighlight multiple-touchables-10 1.60ms 2.00ms ±0.52ms 1 -33.3%
TouchableHighlight multiple-touchables-50 8.80ms 9.00ms ±1.32ms 1 -28.0%
TouchableHighlight multiple-touchables-100 17.00ms 17.00ms ±1.49ms 1 -24.4%

Pressable

Scenario Mean Median StdDev Renders vs Baseline
Pressable mount 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Pressable rerender 0.30ms 0.00ms ±0.48ms 2 -100.0%
Pressable with-all-handlers 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable with-style-function 0.30ms 0.00ms ±0.48ms 1 +0.0%
Pressable disabled 0.20ms 0.00ms ±0.42ms 1 +0.0%
Pressable with-hit-slop 0.20ms 0.00ms ±0.42ms 1 +0.0%
Pressable nested 0.50ms 0.50ms ±0.53ms 1 -50.0%
Pressable multiple-10 1.87ms 2.00ms ±0.52ms 1 -33.3%
Pressable multiple-50 10.40ms 10.00ms ±1.59ms 1 -28.6%
Pressable multiple-100 22.07ms 14.00ms ±19.81ms 1 +16.7%

Modal

Scenario Mean Median StdDev Renders vs Baseline
Modal mount 0.50ms 0.00ms ±0.97ms 1 +0.0%
Modal unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Modal rerender 0.40ms 0.00ms ±0.52ms 2 +0.0%
Modal slide-animation 0.30ms 0.00ms ±0.48ms 1 +0.0%
Modal fade-animation 0.10ms 0.00ms ±0.32ms 1 +0.0%
Modal transparent 0.20ms 0.00ms ±0.42ms 1 +0.0%
Modal with-callbacks 0.30ms 0.00ms ±0.48ms 1 +0.0%
Modal rich-content 1.10ms 1.00ms ±0.32ms 1 -50.0%
Modal with-accessibility 0.20ms 0.00ms ±0.42ms 1 +0.0%

Image

Scenario Mean Median StdDev Renders vs Baseline
Image mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Image rerender 0.20ms 0.00ms ±0.42ms 2 +0.0%
Image with-resize-mode 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-border-radius 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-tint-color 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-blur-radius 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image with-accessibility 0.10ms 0.00ms ±0.32ms 1 +0.0%
Image multiple-10 0.60ms 1.00ms ±0.51ms 1 +0.0%
Image multiple-50 2.40ms 2.00ms ±0.51ms 1 -33.3%
Image multiple-100 5.67ms 5.00ms ±1.18ms 1 -37.5%

ActivityIndicator

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
ActivityIndicator unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
ActivityIndicator rerender 0.10ms 0.00ms ±0.32ms 2 +0.0%
ActivityIndicator size-large 0.00ms 0.00ms ±0.00ms 1 +0.0%
ActivityIndicator size-small 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator with-color 0.10ms 0.00ms ±0.32ms 1 +0.0%
ActivityIndicator not-animating 0.00ms 0.00ms ±0.00ms 1 +0.0%
ActivityIndicator with-accessibility 0.20ms 0.00ms ±0.42ms 1 +0.0%
ActivityIndicator multiple-10 0.67ms 1.00ms ±0.49ms 1 +0.0%
ActivityIndicator multiple-50 2.53ms 3.00ms ±0.52ms 1 -25.0%
ActivityIndicator multiple-100 5.60ms 5.00ms ±1.06ms 1 -28.6%

Switch

Scenario Mean Median StdDev Renders vs Baseline
Switch mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Switch rerender 0.20ms 0.00ms ±0.42ms 2 -100.0%
Switch value-true 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch disabled 0.10ms 0.00ms ±0.32ms 1 +0.0%
Switch custom-colors 0.30ms 0.00ms ±0.48ms 1 +0.0%
Switch on-value-change 0.20ms 0.00ms ±0.42ms 1 +0.0%
Switch with-accessibility 0.10ms 0.00ms ±0.32ms 1 +0.0%
Switch multiple-10 1.27ms 1.00ms ±1.03ms 1 -50.0%
Switch multiple-50 6.67ms 6.00ms ±2.23ms 1 -33.3%
Switch multiple-100 13.00ms 11.00ms ±3.16ms 1 -31.3%

Button

Scenario Mean Median StdDev Renders vs Baseline
Button mount 0.40ms 0.00ms ±0.52ms 1 -100.0%
Button unmount 0.10ms 0.00ms ±0.32ms 0 +0.0%
Button rerender 0.60ms 1.00ms ±0.52ms 2 +0.0%
Button disabled 0.40ms 0.00ms ±0.52ms 1 -100.0%
Button with-color 0.40ms 0.00ms ±0.52ms 1 -100.0%
Button with-accessibility 0.40ms 0.00ms ±0.52ms 1 -100.0%
Button multiple-10 4.07ms 4.00ms ±1.03ms 1 -33.3%
Button multiple-50 14.40ms 17.00ms ±5.65ms 1 -37.0%
Button multiple-100 11.20ms 11.00ms ±1.82ms 1 -42.1%

TextInput

Scenario Mean Median StdDev Renders vs Baseline
TextInput mount 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
TextInput rerender 0.30ms 0.00ms ±0.48ms 2 +0.0%
TextInput multiline 0.20ms 0.00ms ±0.42ms 1 +0.0%
TextInput with-value 0.10ms 0.00ms ±0.32ms 1 +0.0%
TextInput styled 0.10ms 0.00ms ±0.32ms 1 +0.0%
TextInput multiple-100 5.47ms 5.00ms ±1.19ms 1 -28.6%

View

Scenario Mean Median StdDev Renders vs Baseline
View mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
View unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
View rerender 0.60ms 0.00ms ±1.26ms 2 +0.0%
View nested-50 2.53ms 3.00ms ±0.52ms 1 +0.0%
View nested-100 6.13ms 6.00ms ±1.30ms 1 -14.3%
View shadow 0.00ms 0.00ms ±0.00ms 1 +0.0%
View border-radius 0.10ms 0.00ms ±0.32ms 1 +0.0%
View nested-500 13.00ms 8.00ms ±9.35ms 1 -20.0%

Text

Scenario Mean Median StdDev Renders vs Baseline
Text mount 0.10ms 0.00ms ±0.32ms 1 +0.0%
Text unmount 0.00ms 0.00ms ±0.00ms 0 +0.0%
Text rerender 0.00ms 0.00ms ±0.00ms 2 +0.0%
Text long-1000 0.00ms 0.00ms ±0.00ms 1 +0.0%
Text nested 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text styled 0.20ms 0.00ms ±0.42ms 1 +0.0%
Text multiple-100 6.13ms 6.00ms ±1.60ms 1 -14.3%

SectionList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
SectionList native mount 3.72ms 3.51ms ±0.56ms 1 -46.0%

FlatList.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
FlatList native mount 3.43ms 3.13ms ±0.69ms 1 -66.1%

TouchableHighlight.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableHighlight native mount 1.20ms 1.14ms ±0.20ms 1 -45.2%

TouchableOpacity.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TouchableOpacity native mount 1.33ms 1.33ms ±0.13ms 1 -57.5%

Pressable.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Pressable native mount 1.18ms 1.18ms ±0.08ms 1 -52.8%

ScrollView.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ScrollView native mount 2.53ms 2.54ms ±0.14ms 1 -37.2%

ActivityIndicator.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
ActivityIndicator native mount 0.98ms 0.90ms ±0.19ms 1 -63.8%

TextInput.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
TextInput native mount 1.56ms 1.38ms ±0.56ms 1 -66.3%

Switch.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Switch native mount 0.81ms 0.79ms ±0.13ms 1 -54.3%

Button.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Button native mount 1.42ms 1.44ms ±0.12ms 1 -44.5%

Modal.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Modal native mount 0.66ms 0.62ms ±0.11ms 1 -48.9%

Image.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Image native mount 1.52ms 1.24ms ±0.84ms 1 -45.2%

View.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
View native mount 0.86ms 0.81ms ±0.25ms 1 -43.4%

Text.native-perf-test.ts

Scenario Mean Median StdDev Renders vs Baseline
Text native mount 0.97ms 0.88ms ±0.19ms 1 -49.3%

@acoates-ms
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@gmacmaster
Copy link
Copy Markdown
Contributor Author

@acoates-ms these are just the random failures right? Just needs a rerun?

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.

3 participants