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

Is it now possible to use DIO / dio_web_adapter with Web/WASM? #2265

Closed
OsvaldoTCF opened this issue Jul 3, 2024 · 41 comments · Fixed by #2274
Closed

Is it now possible to use DIO / dio_web_adapter with Web/WASM? #2265

OsvaldoTCF opened this issue Jul 3, 2024 · 41 comments · Fixed by #2274
Assignees
Labels
fixed p: dio Targeting `dio` package p: web_adapter Targeting `web_adapter` package platform: web s: feature This issue indicates a feature request

Comments

@OsvaldoTCF
Copy link

OsvaldoTCF commented Jul 3, 2024

Request Statement

$ flutter build web --wasm

I get this error:

.pub-cache/hosted/pub.dev/dio_web_adapter-1.0.1/lib/src/html/adapter.dart:5:8: Error: Dart library 'dart:html' is not available on this platform.
import 'dart:html';
^
Context: The unavailable library 'dart:html' is imported through these packages:

main.dart => package:dio => package:dio_web_adapter => dart:html

Solution Brainstorm

No response

@OsvaldoTCF OsvaldoTCF added the s: feature This issue indicates a feature request label Jul 3, 2024
@AlexV525
Copy link
Member

AlexV525 commented Jul 4, 2024

It does. We're pushing it to convert to the package:web and the code base has already been migrated. Once the package:dio_web_adapter releases v2 you'll be able to use Dio on WASM env.

@AlexV525 AlexV525 added platform: web p: web_adapter Targeting `web_adapter` package labels Jul 4, 2024
@vaind
Copy link

vaind commented Jul 4, 2024

This error started popping up with the latest Dio release and broke our build/tests in getsentry/sentry-dart.

AFAICT, adding the dependency on package web_adapter was a breaking change and should have been a major release (Dio 6.0), not a minor one (Dio 5.5)

@AlexV525
Copy link
Member

AlexV525 commented Jul 4, 2024

This error started popping up with the latest Dio release and broke our build/tests in getsentry/sentry-dart.

Can you elaborate on the details? Please submit an issue at getsentry/sentry-dart and ping me so we can track specific problems. This thread should focus on WASM support.

AFAICT, adding the dependency on package web_adapter was a breaking change and should have been a major release (Dio 6.0), not a minor one (Dio 5.5)

Nope. We intended to make this not a breaking change and the package is still embedded with the package:dio, no implementation has been changed. People who upgrade to Dio v5.5 will automatically use the package:web_adapter.

@vaind
Copy link

vaind commented Jul 4, 2024

This is breaking for people who were alerady building for WASM, because package:web_adapter is incompatible with it while Dio at v5.4 worked fine

@vaind

This comment was marked as off-topic.

@AlexV525
Copy link
Member

AlexV525 commented Jul 4, 2024

Please submit an issue at getsentry/sentry-dart and ping me so we can track specific problems. This thread should focus on WASM support.

@vaind

@vaind
Copy link

vaind commented Jul 4, 2024

This is not an issue in sentry-dart. Your package added a dependency on a noncompatible package. I'll create a new issue.

@Rexios80
Copy link

Rexios80 commented Jul 4, 2024

@vaind What are you talking about? They created dio_web_adapter because dio currently does not support WASM.

../../.pub-cache/hosted/pub.dev/dio-5.4.3+1/lib/src/adapters/browser_adapter.dart:3:8: Error: Dart library 'dart:html' is not available on this platform.
import 'dart:html';

@Rexios80
Copy link

Rexios80 commented Jul 4, 2024

@AlexV525 while we're here, how do you plan on dealing with the possibility of needing to update dio_web_adapter v1 after releasing v2? I'm pretty sure pub won't let you release versions below 2.0.0 after you release it.

@AlexV525
Copy link
Member

AlexV525 commented Jul 4, 2024

I'm pretty sure pub won't let you release versions below 2.0.0 after you release it.

AFAICT it does allow. But maybe it's been changed.

@Rexios80
Copy link

Rexios80 commented Jul 4, 2024

Holy crap it totally does. I did not expect that.

@vaind
Copy link

vaind commented Jul 4, 2024

why wouldn't it? it's another major version - it's pretty normal to have releases on multiple major versions

@vaind
Copy link

vaind commented Jul 4, 2024

@vaind What are you talking about? They created dio_web_adapter because dio currently does not support WASM.

../../.pub-cache/hosted/pub.dev/dio-5.4.3+1/lib/src/adapters/browser_adapter.dart:3:8: Error: Dart library 'dart:html' is not available on this platform.
import 'dart:html';

Depends on what you're using from Dio. See #2266

@kuhnroyal
Copy link
Member

Judging by your sample, with no specific adapter configuration, it seems that the default IO adapter is used for the WASM compile. Which does not really make sense to me, why would that work? I mean I can see that it compiles but....

@AlexV525
Copy link
Member

AlexV525 commented Jul 5, 2024

Judging by your sample, with no specific adapter configuration, it seems that the default IO adapter is used for the WASM compile. Which does not really make sense to me, why would that work? I mean I can see that it compiles but....

I guess that the WASM env is compatible with the compilation of dart:io but no actual business can be involved.

@Rexios80
Copy link

Rexios80 commented Jul 5, 2024

That might be a bug in the WASM compiler

@vaind
Copy link

vaind commented Jul 5, 2024

That might be a bug in the WASM compiler

The compiled code works fine: the request is executed successfully.

@kuhnroyal
Copy link
Member

So from what I read, dart:io seems to be a supported package for WASM. Just can not target any browser API then.
Not sure how a file download etc. will behave at runtime in a browser.

@Rexios80
Copy link

What is the status of dio_web_adapter: 2.0.0? Is there anything I can do to help with the migration?

@kuhnroyal
Copy link
Member

I am interested in some feedback on the usage of the IOHttpClientAdapter in WASM mode. It seems to compile and work. Do we actually need a web adapter for WASM?

@Rexios80
Copy link

Apps can build but you can't actually make any calls

main.dart.mjs:19 DioException [unknown]: null
Error: Unsupported operation: Platform._version
main.dart.mjs:19     at _DioForNative&Object&DioMixin.fetch inner (http://localhost:49762/main.dart.wasm:wasm-function[1369]:0x4a870)
    at _awaitHelper closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:85:15 (http://localhost:49762/main.dart.wasm:wasm-function[2508]:0x6113a)
    at closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:85:15 trampoline (http://localhost:49762/main.dart.wasm:wasm-function[2514]:0x611a6)
    at _RootZone.runBinary (http://localhost:49762/main.dart.wasm:wasm-function[949]:0x42673)
    at _FutureListener.handleError (http://localhost:49762/main.dart.wasm:wasm-function[948]:0x425c2)
    at _Future._propagateToListeners closure handleError at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:868:25 (http://localhost:49762/main.dart.wasm:wasm-function[914]:0x41ee1)
    at _Future._propagateToListeners (http://localhost:49762/main.dart.wasm:wasm-function[910]:0x41ad0)
    at _Future._completeError (http://localhost:49762/main.dart.wasm:wasm-function[1004]:0x43015)
localhost/:1 Uncaught Exception

@OlegShNayax
Copy link

Apps can build but you can't actually make any calls

main.dart.mjs:19 DioException [unknown]: null
Error: Unsupported operation: Platform._version
main.dart.mjs:19     at _DioForNative&Object&DioMixin.fetch inner (http://localhost:49762/main.dart.wasm:wasm-function[1369]:0x4a870)
    at _awaitHelper closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:85:15 (http://localhost:49762/main.dart.wasm:wasm-function[2508]:0x6113a)
    at closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:85:15 trampoline (http://localhost:49762/main.dart.wasm:wasm-function[2514]:0x611a6)
    at _RootZone.runBinary (http://localhost:49762/main.dart.wasm:wasm-function[949]:0x42673)
    at _FutureListener.handleError (http://localhost:49762/main.dart.wasm:wasm-function[948]:0x425c2)
    at _Future._propagateToListeners closure handleError at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:868:25 (http://localhost:49762/main.dart.wasm:wasm-function[914]:0x41ee1)
    at _Future._propagateToListeners (http://localhost:49762/main.dart.wasm:wasm-function[910]:0x41ad0)
    at _Future._completeError (http://localhost:49762/main.dart.wasm:wasm-function[1004]:0x43015)
localhost/:1 Uncaught Exception

We have same issue in our project. Apps can build in wasm mode but there are no actually performing any calls.

Any updates about status of dio_web_adapter: 2.0.0 ?

@kuhnroyal
Copy link
Member

@vaind How did you test your requests?

@vaind
Copy link

vaind commented Jul 24, 2024

by checking the response

@Rexios80
Copy link

Idk what call you're making but dio.get doesn't work

@Rexios80
Copy link

@vaind are you 100% sure your app is running with the WASM renderer? There are very specific header and browser requirements.

@vaind
Copy link

vaind commented Jul 24, 2024

see my repro here where I've tested it with dio 5.4 #2266 - you can give it a try and print out the the response, to see if it actually works. I remember it worked, although I have no need for dio/wasm personally so that repro was just to get the plugin fixed to unbreak my builds elsewhere

@Rexios80
Copy link

Can you check the value of bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM')?

@vaind
Copy link

vaind commented Jul 24, 2024

Can you check the value of bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM')?

Sorry, I don't have the environment to do that anymore but you can try it yourself with the given example. Or just wait until official wasm support lands in Dio

@Rexios80
Copy link

you can try it yourself with the given example

Your example is pretty much what I created myself

Or just wait until official wasm support lands in Dio

Your claims that requests work when compiled to WASM seem to be what is blocking work on that support

The compiled code works fine: the request is executed successfully.

In the future please check the value of bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM') before making any claims about what does and doesn't work when compiled to WASM. I looked at the sentry-dio tests and there are only mocked requests which is why they aren't failing. See the Flutter WASM docs for information about running the WASM renderer.

@vaind
Copy link

vaind commented Jul 24, 2024

In the future please check the value of bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM')

I'll do that. Maybe it just falled back on .js or something. As I've said, I have no need for wasm+dio so I didn't looked too much into it and I must have gotten fooled by it showing stuff when I launched the built app.

@Rexios80
Copy link

@kuhnroyal Is there existing work on dio_web_adapter: 2.0.0? If not and no one is assigned to it I can take a look.

@kuhnroyal
Copy link
Member

I think some initial work was done in #2218 but we had to split the adapter first. Feel free to create a PR 👍

@AlexV525
Copy link
Member

@kuhnroyal Is there existing work on dio_web_adapter: 2.0.0? If not and no one is assigned to it I can take a look.

The implementation has already been setup with src/js_interop, the remaining things are:

  1. We need to update our CI to work with WASM.
  2. We have a Web-related pull request but not making good progress Add support for download function in web #2230
  3. Other misc checks.

Self-assigned since I've already done most of the work. This could be pushed in the next few days, I've been through a busy month recently :).

@AlexV525 AlexV525 self-assigned this Jul 26, 2024
@Rexios80
Copy link

@AlexV525 Thank you! I need this soon for an upcoming project, so if you need any help with the migration or testing please let me know!

@AlexV525
Copy link
Member

@AlexV525 Thank you! I need this soon for an upcoming project, so if you need any help with the migration or testing please let me know!

For personal usages I'd recommend to easily fork and update the code like this: https://github.com/cfug/dio/pull/2274/files
The official support could be generally served for downstream package usages and provide a solid solution.

@Rexios80
Copy link

Yes that would work as a last resort, but I'd rather not start a new project with a bunch of self-hosted dependencies if I can avoid it

@AlexV525
Copy link
Member

Yes that would work as a last resort, but I'd rather not start a new project with a bunch of self-hosted dependencies if I can avoid it

or rely on this ref-based dependency: e247bd0

@selimb86
Copy link

Will the 'dio_web_adapter' v2 support SSE (Streaming) ?

@OlegShNayax
Copy link

Any update about release of this version of dio?

@AlexV525
Copy link
Member

We've published dio v5.6.0 and dio_web_adapter v2.0.0 to support the WASM environment. Please submit separate issues regarding specific implementations if any.

@cfug cfug locked as resolved and limited conversation to collaborators Aug 13, 2024
@AlexV525 AlexV525 added p: dio Targeting `dio` package fixed labels Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed p: dio Targeting `dio` package p: web_adapter Targeting `web_adapter` package platform: web s: feature This issue indicates a feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants