Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Eval Prematurely Dropping #3877

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/desktop/src/js/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[14101548031762241351]
[16018260687765471498]
2 changes: 1 addition & 1 deletion packages/desktop/src/js/native_eval.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/desktop/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl QueryEngine {
let promise = (new AsyncFunction("dioxus", {script:?}))(dioxus);
promise
.then((result)=>{{
dioxus.close();
let returned_value = {{
"method": "query",
"params": {{
Expand All @@ -96,6 +97,7 @@ impl QueryEngine {
}})
.catch(err => post_error(`Error running JS: ${{err}}`));
}} catch (error) {{
dioxus.close();
post_error(`Invalid JS: ${{error}}`);
}}
}})();"#
Expand Down
7 changes: 6 additions & 1 deletion packages/desktop/src/ts/native_eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NativeDioxusChannel extends DioxusChannel {
this.rust_to_js = new Channel();
this.request_id = request_id;

window.__msg_queues[request_id] = this.weak();
window.__msg_queues[request_id] = this;
window.finalizationRegistry.register(this, { id: request_id });
}

Expand All @@ -87,4 +87,9 @@ export class NativeDioxusChannel extends DioxusChannel {

// Receive data sent from javascript in rust. This is a no-op in the native interpreter because the rust code runs remotely
async rustRecv(): Promise<any> { }

// Close the channel, dropping it.
close(): void {
window.__msg_queues[this.request_id] = null;
}
}
2 changes: 1 addition & 1 deletion packages/document/src/js/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[206827801705263822, 8375185156499858125]
[5568016277461366671, 8375185156499858125]
3 changes: 3 additions & 0 deletions packages/document/src/ts/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ export abstract class DioxusChannel {

// Receive data sent from javascript in rust
abstract rustRecv(): Promise<any>;

// Close the channel, dropping it.
abstract close(): void;
}
2 changes: 2 additions & 0 deletions packages/web/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl Document for WebDocument {
const PROMISE_WRAPPER: &str = r#"
return (async function(){
{JS_CODE}

dioxus.close();
})();
"#;

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/js/eval.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/web/src/js/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[1614426347475783279]
[857504888396904142]
13 changes: 13 additions & 0 deletions packages/web/src/ts/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import {
WeakDioxusChannel,
} from "../../../document/src/ts/eval";

window.__nextChannelId = 0;
window.__channels = [];

export class WebDioxusChannel extends DioxusChannel {
js_to_rust: Channel;
rust_to_js: Channel;
owner: any;
id: number;

constructor(owner: any) {
super();
this.owner = owner;
this.js_to_rust = new Channel();
this.rust_to_js = new Channel();

this.id = window.__nextChannelId;
window.__channels[this.id] = this;
window.__nextChannelId += 1;
}

// Return a weak reference to this channel
Expand All @@ -40,4 +48,9 @@ export class WebDioxusChannel extends DioxusChannel {
async rustRecv(): Promise<any> {
return await this.js_to_rust.recv();
}

// Close the channel, dropping it.
close(): void {
window.__channels[this.id] = null;
}
}
Loading