Skip to content

[WASM] Failed to check runtimeType in release mode #16

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

Closed
hnvn opened this issue Apr 2, 2025 · 3 comments
Closed

[WASM] Failed to check runtimeType in release mode #16

hnvn opened this issue Apr 2, 2025 · 3 comments

Comments

@hnvn
Copy link

hnvn commented Apr 2, 2025

This code line won't work on release mode for Flutter WASM:

if (encodedPacket.runtimeType.toString() == 'JSValue') {

@jumperchen
Copy link
Member

Perhaps we need to have this API ready first. - dart-lang/sdk#56905

@jumperchen
Copy link
Member

@hnvn Could you apply with the following diff into your runtime project to see if it works in release mode?

diff --git a/lib/src/engine/parser/decodePacket.dart b/lib/src/engine/parser/decodePacket.dart
index 0fd85b0..672410f 100644
--- a/lib/src/engine/parser/decodePacket.dart
+++ b/lib/src/engine/parser/decodePacket.dart
@@ -4,7 +4,7 @@
 
 import 'dart:convert';
 import 'dart:typed_data';
-
+import 'dart:js_interop';
 import 'commons.dart';
 
 mapBinary(data, binaryType) {
@@ -17,7 +17,7 @@ mapBinary(data, binaryType) {
 
 decodePacket(dynamic encodedPacket, binaryType) {
   // a workaround for Flutter web WASM
-  if (encodedPacket.runtimeType.toString() == 'JSValue') {
+  if (encodedPacket is JSString) {
     encodedPacket = '$encodedPacket'; // force to String type in dart
   }
   if (encodedPacket is! String) {

@hnvn
Copy link
Author

hnvn commented Apr 3, 2025

@jumperchen This solution works well in release mode for Flutter Web WASM, but it causes build error in other platforms:

Error (Xcode): ../../../.pub-cache/git/socket_io_common-2d37d94cc491c9ef943f434c4effc7a712eaf81b/lib/src/engine/parser/decodePacket.dart:6:8: Error: Dart library 'dart:js_interop' is not available on this platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants