Closed anlumo closed 1 year ago
/cc @Desdaemon who implemented the great web part :)
So, the main issue is that the Dart code is casting types around all the time (from subclass to superclass, back to subclass, etc), and the js interop can't cope with that.
In release mode with -O3, the type checks are simply omitted. I haven't found a way yet to remove them in debug mode. Also, this seems to be a bad idea to do globally anyways.
Right now I'm trying to get the generated code to not do any casting in the first place, but as this is the fourth day I'm spending on this, I'm running out of time and might have to scratch flutter_rust_bridge completely for the project.
This means that there's no debugging and no hot reload on that target, which makes it pretty much impossible to develop.
Btw flutter itself does not support hot reload (though support hot restart), on Web
Yeah, I meant hot restart. The debugging is the bigger issue anyways.
So, an update:
I've finally managed to fix the issue in my fork. It's mostly adjusting the data flow to use generics instead of casting the type of the wasm_bindgen
LegacyJavaScriptObject
(which doesn't work).
I've also managed to fix the simplified initialization shown in the documentation here, which is way more complicated than getting it to run in the first place, because there's a weird loading system that's designed for ES modules that don't work with web workers anyways.
Now, I don't know yet how to feed this back into this project, since I don't have any idea how to do tests for this, since it's basically compiler configuration. I'll deal with that later, I need to rebase all of my changes to the latest version first anyways.
Also, there's the question of the development server. Mine is very different than the serve.dart shipped with this project, because I'm doing a reverse proxy server that just relays the flutter run
server (and so hot restart and the Flutter inspector are fully supported). However, it needs a different setup, specifically two extra flags to the flutter run
command (as documented in the ticket description here). So, this would need new documentation.
Also, this dev server does not run the wasm-pack
command, because that's outside of the scope in this architecture (would not be enough to run this on startup when you can change the Rust code during development). This would need some other build system setup like cargo-make, preferably using some kind of file change watcher.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
👀
What about adding coi to web/index.html in the \
section ? https://github.com/gzuidhof/coi-serviceworkerThis issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.
Describe the bug
flutter_rust_bridge works when run in profile or release mode on the Web, but not in debug mode. This means that there's no debugging and no hot reload on that target, which makes it pretty much impossible to develop.
The
serve
utility also only runs in profile and release. I'm currently trying to implement my own solution that allows debugging, but I'm running into problems left right and center.My idea is to have the regular
flutter run
serving the page on port 3001, and then having a proxy service running on port 3000 that forwards all requests to port 3001 with the right headers added to the responses. Dart uses a websocket for debugging, but I can simply redirect that to the original port, since I don't have to change any headers for that one and websockets don't have CORS issues.To Reproduce
I created a simple proxy in Rust for serving the Flutter code with the right HTTP headers:
Then in
index.html
, I have to change the websocket URL and load canvaskit from a local path:Then I have to update the launch configuration of vsc:
My loader code:
(Note that I had to implement all of that myself instead of using
Modules.noModules
in order to implement error checking, because the dart2js compiler produces JavaScript code that doesn't propagate exceptions in async contexts.)This is the error I get (from the
catch
above):My research indicates that this might be caused by the
@JS
and@anonymous
annotations of theNativeWasmModule
class not being frompackage:js
, but being homebrewn inside flutter_rust_bridge. The official annotations with the same name are used by the Dart compiler to do typecasts differently (according to the documentation, I haven't found the code for that yet), so this might be the reason why it can't cast aJsObject
(which is the superclass ofLegacyJavaScriptObject
) to ananonymous
class, which should work fine, according to the Dart documentation. (EDIT: usingpackage:js
's annotations doesn't fix it.)I suspect that non-debug profiles simply skip the type checking and that's the reason why it works there. Again, I haven't found the code in the Dart compiler for that yet, though.
Expected behavior
Everything runs fine without exceptions.
Version of
flutter_rust_bridge_codegen
1.61.1 (with my PRs applied)
Flutter info