fix(core): raw channel message type regression (#13268)

* Fix raw channel message type regression

* Re-word change file

* Rename formated_bytes to bytes_as_json_array
This commit is contained in:
Tony 2025-04-21 10:26:00 +08:00 committed by GitHub
parent 87fdc3b9cd
commit da2a6ae5e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
tauri: patch:bug
---
Fix a regression that made the raw type messages received from `Channel.onmessage` became `number[]` instead of `ArrayBuffer` when that message is small

View File

@ -154,9 +154,9 @@ impl JavaScriptChannelId {
))?;
}
InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
let bytes_as_json_array = serde_json::to_string(&bytes)?;
webview.eval(format!(
"window['_{callback_id}']({{ message: {}, index: {current_index} }})",
serde_json::to_string(&bytes)?,
"window['_{callback_id}']({{ message: new Uint8Array({bytes_as_json_array}).buffer, index: {current_index} }})",
))?;
}
// use the fetch API to speed up larger response payloads
@ -246,9 +246,9 @@ impl<TSend> Channel<TSend> {
webview.eval(format!("window['_{callback_id}']({string})"))?;
}
InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
let bytes_as_json_array = serde_json::to_string(&bytes)?;
webview.eval(format!(
"window['_{callback_id}']({})",
serde_json::to_string(&bytes)?,
"window['_{callback_id}'](new Uint8Array({bytes_as_json_array}).buffer)",
))?;
}
// use the fetch API to speed up larger response payloads