sdk
sdk copied to clipboard
Error: "Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead" during Flutter web hot reload.
Getting a bunch of the lines bellow on Flutter web during Hot reload:
6586/dart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 89:7 JSBoxedDartObjectToObject.get$35toDart
http://localhost:56586/lib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 574:37 _checkAndCall
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 579:39 dcall
Error: Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead.
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw_
http://localhost:56586/dart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 89:7 JSBoxedDartObjectToObject.get$35toDart
http://localhost:56586/lib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 574:37 _checkAndCall
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 579:39 dcall
Error: Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead.
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw_
http://localhost:56586/dart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 89:7 JSBoxedDartObjectToObject.get$35toDart
http://localhost:56586/lib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 574:37 _checkAndCall
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 579:39 dcall
Error: Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead.
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:3 throw_
http://localhost:56586/dart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 89:7 JSBoxedDartObjectToObject.get$35toDart
http://localhost:56586/lib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 574:37 _checkAndCall
http://localhost:56586/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 579:39 dcall
-
Dart version and tooling diagnostic info (
dart info)- Dart SDK version: 3.2.4 (stable) (Thu Dec 21 19:13:53 2023 +0000) on "macos_arm64"
-
Whether you are using Windows, macOS, or Linux (if applicable)
- Mac
-
Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
- Chrome
@pedromassango any progress here? how did you resolve?
@pedromassango any progress here? how did you resolve?
No, still facing
Seeing the same error - constantly logging and eventually causes Chrome to die
I'm seeing similar errors on Dart-Code's integration tests on the current Flutter stable. For example the "stops at a breakpoint after each hot reload" test fails with:
Error: Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead.
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_
dart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 93:7 JSBoxedDartObjectToObject.get$35toDart
lib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 550:37 _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 555:39 dcall
The exception appears in the pause reason (we expect "breakpoint" as the pause reason but get this exception):
[3:52:27 PM] [General] [Info] [stdout] [ +4 ms] DevHandler: VmService proxy responded with an error:
[3:52:27 PM] [DAP] [Info] <== {"seq":1152,"type":"event","event":"dart.log","body":{"message":"<== {jsonrpc: 2.0, id: 43, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 43, params: {streamId: Isolate, includePrivateMembers: false}}}}\r\n","severity":0,"category":9}}
[3:52:27 PM] [FlutterRun] [Info] [Dart & Flutter (flutter run debugger (launch on chrome) stops at a breakpoint after each reload (1))] <== {jsonrpc: 2.0, id: 43, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 43, params: {streamId: Isolate, includePrivateMembers: false}}}}
[3:52:27 PM] [DAP] [Info] <== {"seq":1153,"type":"event","event":"output","body":{"category":"stdout","output":" {jsonrpc: 2.0, id: 43, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 43, params: {streamId: Isolate, includePrivateMembers: false}}}}\n"}}
[3:52:27 PM] [General] [Info] [stdout] {jsonrpc: 2.0, id: 43, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 43, params: {streamId: Isolate, includePrivateMembers: false}}}}
[3:52:27 PM] [DAP] [Info] <== {"seq":1154,"type":"event","event":"stopped","body":{"reason":"exception","threadId":1,"text":"\"Error: Expected a wrapped Dart object, but got a JS object or a wrapped Dart object from a separate runtime instead.\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_\ndart-sdk/lib/_internal/js_shared/lib/js_interop_patch.dart 93:7 JSBoxedDartObjectToObject.get$35toDart\nlib/_engine/engine/canvaskit/native_memory.dart 24:46 <fn>\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 550:37 _checkAndCall\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 555:39 dcall\n\""}}
@elliette I was going to raise this in the webdev repo before I found this existing issue here. It's not clear to me where the problem lies though - could this be DWDS?
(I've not been able to reproduce it locally on Windows.. I'm seeing it on Ubuntu bots)
@srujzs and I did an investigation today and here are some notes:
The .toDart getter call here is throwing:
https://github.com/flutter/engine/blob/23467e04433d848ed5e074b0997a1be9296e4077/lib/web_ui/lib/src/engine/canvaskit/native_memory.dart#L25
The getter implementation is here: https://github.com/dart-lang/sdk/blob/74baf5e75a754edff091785586214549124c0c18/sdk/lib/_internal/js_shared/lib/js_interop_patch.dart#L95-L102 The getter does some verification to ensure the value came from the current Dart app by comparing an attached symbol to a top level field in the Dart SDK. In normal app execution this should work as expected.
Our current theory is that It seems like the finalization gets triggered at some point after the restarts. This make sense because it would have to be after the value gets garbage collected which probably doesn't happen until the app is restarted. We think the getter throws because the app has been restarted and the top level symbol used to identify the app has been reinitialized so they no longer match. This hasn't been confirmed 100% because it is difficult (impossible?) to debug the code that runs in the finalizer callback using chrome devtools.
A workaround (not sure if this is a good idea or not) we could investigate would be to force the _jsBoxedDartObjectProperty not to be reinitialized during the hot restart. This would be different from all the other static fields in the program but it would mean from the view of the .toDart getter the value came from the current Dart application.
I'd also be curious to see if something triggered this to happen recently. Both the Flutter and relevant Dart code has existed in stable for several months now, so I'm surprised to see an issue pop up now instead of earlier.
Based on comments here and https://github.com/flutter/flutter/issues/140684 this doesn't seem likely to be DWDS-related, but let me know if I can do any investigation to help.
Both the Flutter and relevant Dart code has existed in stable for several months now, so I'm surprised to see an issue pop up now instead of earlier.
For my integration tests, the Chrome debug adapter tests have always been a little flaky (it's the legacy ones failing and not the new SDK debug adapters) so it's possible they've been failing for a while but I only recently realised it was a consistency failure and not just flakes. I'm also only running the tests on stable for all checkins, so if "several months" means it only went to stable in the recent release, that could also be a reason I hadn't seen it earlier.
I can try to pinpoint which release it started failing with this consistently if that's useful, but since I can't repro locally it'd be by triggering the bots with the recent release numbers and reviewing the results.
I'm also only running the tests on stable for all checkins, so if "several months" means it only went to stable in the recent release, that could also be a reason I hadn't seen it earlier.
This code went in for the 3.2 release, but I suppose that wasn't too long ago, and the flakes could explain the gap.
I can try to pinpoint which release it started failing with this consistently if that's useful, but since I can't repro locally it'd be by triggering the bots with the recent release numbers and reviewing the results.
A range could help too if it's too difficult to pinpoint - I'd mostly be curious to see if this existed 3.2 onwards or just started to materialize. Thanks!
For my integration tests, the Chrome debug adapter tests have always been a little flaky (it's the legacy ones failing and not the new SDK debug adapters)
FWIW I just saw this failure on the new SDK debug adapters too. I guess it's timing-dependant and the legacy adapters just happen to get the right (wrong) timing frequently and the new ones rarely (there probably many small differences between them, legacy one TypeScript and the new one is a Dart re-implementation).
what the heck . how to resolve this erorr ?