Skip to content

Commit da2a6ae

Browse files
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
1 parent 87fdc3b commit da2a6ae

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: patch:bug
3+
---
4+
5+
Fix a regression that made the raw type messages received from `Channel.onmessage` became `number[]` instead of `ArrayBuffer` when that message is small

crates/tauri/src/ipc/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ impl JavaScriptChannelId {
154154
))?;
155155
}
156156
InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
157+
let bytes_as_json_array = serde_json::to_string(&bytes)?;
157158
webview.eval(format!(
158-
"window['_{callback_id}']({{ message: {}, index: {current_index} }})",
159-
serde_json::to_string(&bytes)?,
159+
"window['_{callback_id}']({{ message: new Uint8Array({bytes_as_json_array}).buffer, index: {current_index} }})",
160160
))?;
161161
}
162162
// use the fetch API to speed up larger response payloads
@@ -246,9 +246,9 @@ impl<TSend> Channel<TSend> {
246246
webview.eval(format!("window['_{callback_id}']({string})"))?;
247247
}
248248
InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
249+
let bytes_as_json_array = serde_json::to_string(&bytes)?;
249250
webview.eval(format!(
250-
"window['_{callback_id}']({})",
251-
serde_json::to_string(&bytes)?,
251+
"window['_{callback_id}'](new Uint8Array({bytes_as_json_array}).buffer)",
252252
))?;
253253
}
254254
// use the fetch API to speed up larger response payloads

0 commit comments

Comments
 (0)