fix: channel callback never cleaned up from window#13136
Conversation
Package Changes Through ebb919bThere are 8 changes which include @tauri-apps/api with minor, tauri with minor, tauri-bundler with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, @tauri-apps/cli with minor, tauri-cli with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
This change will require syncing the version of rust crate |
|
hmm, yeah. we've communicated that minor versions are synced a few times (even if we don't fully follow it) so it should be fine. not the first time in 2.x either 🤷 |
| "window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window['_' + {}]({{ message: response, id: {i} }})).catch(console.error)", | ||
| callback_id.0 | ||
| ))?; | ||
| // Don't go through the fetch process if the payload is small |
There was a problem hiding this comment.
finally someone who agrees with me on that approach 😂
There was a problem hiding this comment.
This should significantly reduce the load in places like sending updater's download progress
|
sample benchmark script: pub fn spam(channel: Channel<tauri::ipc::InvokeResponseBody>) -> tauri::Result<()> {
for i in 1..=255 {
channel.send(tauri::ipc::InvokeResponseBody::Raw(
std::iter::repeat(i).take(1024).collect(),
))?;
}
Ok(())
}(change 1024 to whatever you want to test) channel = new __TAURI__.core.Channel();
i = 0;
channel.onmessage = (m) => {console.log(m); i++; if (i === 255) { console.timeEnd('spam') } };
console.time('spam');
__TAURI__.core.invoke('spam', { channel }); |
| InvokeResponseBody::Raw(bytes) if bytes.len() < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => { | ||
| webview.eval(format!( | ||
| "window['_{callback_id}']({{ message: {}, index: {current_index} }})", | ||
| serde_json::to_string(&bytes)?, |
There was a problem hiding this comment.
@Legend-Master This is a BREAKING CHANGE.
I need to use channels to send binary data:
- https://github.com/pytauri/pytauri/blob/c738a5949859455e89e8095df1d0726831c29f1a/crates/tauri-plugin-pytauri/guest-js/src/index.ts#L94-L97
- https://github.com/pytauri/pytauri/blob/c738a5949859455e89e8095df1d0726831c29f1a/crates/pytauri-core/src/ext_mod_impl/ipc.rs#L301
Previously, the received data was an ArrayBuffer, but now it has become an Array.
There was a problem hiding this comment.
That's pretty much the only part not written by me in this PR (ebb919b) 😅, anyways, I'll take a look tomorrow
There was a problem hiding this comment.
Oh, my bad, I didn't notice that 😂
Fix #13133
Also:
Channelso you can use it like thisnew Channel((message) => console.log(message))