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

Provide a compatible method to conditionally import between WASM and regular Web with also backward compatibility #55796

Closed
AlexV525 opened this issue May 21, 2024 · 5 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.

Comments

@AlexV525
Copy link
Contributor

AlexV525 commented May 21, 2024

Dio is embedded with the Web HTTP request support based on dart:html. It also widely supports Dart SDK >=2.18.0 applications.

During the release of the WASM support, the package:web requires Dart SDK >=3.3.0 which is way smaller than our supported range.

Many contributors including ourselves have tried to find a static way to split the Web support into packages without making any breaking changes, but that seems impossible because we need a compatible way to conditionally import libraries based on the environment, which is not provided by Dart if you applied the above restrictions.

Please consider supporting the request or kindly provide a workaround, because there are millions of applications that are using Dio. Huge thanks for any input.

@Rexios80
Copy link
Contributor

What if you do something like:

import 'stub.dart'
  if (dart.library.html) 'html_impl.dart'
  if (dart.library.js_interop) 'js_interop_impl.dart';

If the evaludation is short circuited, then the html implementation should be used on old web platforms and the js_interop implementation should be used on WASM.

@AlexV525
Copy link
Contributor Author

What if you do something like:

import 'stub.dart'
  if (dart.library.html) 'html_impl.dart'
  if (dart.library.js_interop) 'js_interop_impl.dart';

If the evaludation is short circuited, then the html implementation should be used on old web platforms and the js_interop implementation should be used on WASM.

This could work if the condition is not running into any compile issues.

@mit-mit mit-mit added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label May 22, 2024
@sigmundch sigmundch added the area-dart2wasm Issues for the dart2wasm compiler. label May 22, 2024
@sigmundch
Copy link
Member

Potentially we could treat this as a duplicate of #55694?

cc @osa1

@osa1
Copy link
Member

osa1 commented May 22, 2024

Potentially we could treat this as a duplicate of #55694?

Yes, I think this is a duplicate #55694.

@sigmundch
Copy link
Member

I'll close this so we can track the idea of the new condition in the other issue.

I forgot to mention - the workaround suggested by @Rexios80 above is also what we recommend for distinguishing runtimes under the current available conditional import conditions.

dart:html is supported in JavaScript compilers (DDC and dart2js) and not Wasm, so dart.library.html can be used to distinguish between the various JS runtimes, similarly dart.library.js_interop helps distinguish wasm from the VM runtime.

In the past some people have used js and js_util, but it's likely those will not be supported in Wasm in the future, and as such, we normally recommend using .js_interop instead.

This could work if the condition is not running into any compile issues.

Can you clarify what's your concern? I'm not sure I follow

@sigmundch sigmundch closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.
Projects
None yet
Development

No branches or pull requests

5 participants