Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@natebosch
Copy link
Contributor

Splitting from #46592 to separate code changes from the package roll.

Splitting from flutter#46592 to separate code changes from the package roll.
@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 13, 2023
@natebosch
Copy link
Contributor Author

@yjbanov

I'm not able to find any useful logs about what is failing here. Do you know how to track down the error?

@natebosch
Copy link
Contributor Author

Ah, I was able to find a more useful log.

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8767321712197705569/+/u/test:_run_suite_chrome-dart2js-html-html/stdout

it looks like upgrading test causes web tests to all fail.

That's probably because test has not been updated since I changed the communication between the frame and host, and I never noticed another copied implementation in this repo.

@natebosch
Copy link
Contributor Author

natebosch commented Oct 13, 2023

OK, this repo made a copy of host.dart with some significant edits.

1,3c1,3
< // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
< // for details. All rights reserved. Use of this source code is governed by a
< // BSD-style license that can be found in the LICENSE file.
---
> // Copyright 2013 The Flutter Authors. All rights reserved.
> // Use of this source code is governed by a BSD-style license that can be
> // found in the LICENSE file.
49c49
< final _iframes = Map<int, IFrameElement>();
---
> final Map<int, IFrameElement> _iframes = <int, IFrameElement>{};
52c52
< final _subscriptions = Map<int, List<StreamSubscription>>();
---
> final Map<int, List<StreamSubscription<dynamic>>> _subscriptions = <int, List<StreamSubscription<dynamic>>>{};
55c55
< final _currentUrl = Uri.parse(window.location.href);
---
> final Uri _currentUrl = Uri.parse(window.location.href);
118,119c118,119
<     var serverChannel = _connectToServer();
<     serverChannel.stream.listen((message) {
---
>     final MultiChannel<dynamic> serverChannel = _connectToServer();
>     serverChannel.stream.listen((dynamic message) {
121,124c121,125
<         var suiteChannel =
<             serverChannel.virtualChannel(message['channel'] as int);
<         var iframeChannel =
<             _connectToIframe(message['url'] as String, message['id'] as int);
---
>         final int channelId = message['channel'];
>         final String url = message['url'];
>         final int messageId = message['id'];
>         final VirtualChannel<dynamic> suiteChannel = serverChannel.virtualChannel(channelId);
>         final StreamChannel<dynamic> iframeChannel = _connectToIframe(url, messageId);
134c135
<         for (var subscription in _subscriptions.remove(message['id'])) {
---
>         for (StreamSubscription<dynamic> subscription in _subscriptions.remove(message['id'])) {
143,149c144
<         (_) => serverChannel.sink.add({'command': 'ping'}));
< 
<     var play = document.querySelector('#play');
<     play.onClick.listen((_) {
<       if (!document.body.classes.remove('paused')) return;
<       serverChannel.sink.add({'command': 'resume'});
<     });
---
>         (_) => serverChannel.sink.add(<String, String>{'command': 'ping'}));
152,153c147,150
<       if (!document.body.classes.remove('paused')) return;
<       serverChannel.sink.add({'command': 'resume'});
---
>       if (!document.body.classes.remove('paused')) {
>         return;
>       }
>       serverChannel.sink.add(<String, String>{'command': 'resume'});
155c152
<       serverChannel.sink.add({'command': 'restart'});
---
>       serverChannel.sink.add(<String, String>{'command': 'restart'});
157c154
<   }, onError: (error, StackTrace stackTrace) {
---
>   }, onError: (dynamic error, StackTrace stackTrace) {
164c161
< MultiChannel _connectToServer() {
---
> MultiChannel<dynamic> _connectToServer() {
167c164
<   var webSocket = WebSocket(_currentUrl.queryParameters['managerUrl']);
---
>   final WebSocket webSocket = WebSocket(_currentUrl.queryParameters['managerUrl']);
169,171c166,169
<   var controller = StreamChannelController(sync: true);
<   webSocket.onMessage.listen((message) {
<     controller.local.sink.add(jsonDecode(message.data as String));
---
>   final StreamChannelController<dynamic> controller = StreamChannelController<dynamic>(sync: true);
>   webSocket.onMessage.listen((MessageEvent message) {
>     final String data = message.data;
>     controller.local.sink.add(jsonDecode(data));
175c173
<       .listen((message) => webSocket.send(jsonEncode(message)));
---
>       .listen((dynamic message) => webSocket.send(jsonEncode(message)));
177c175
<   return MultiChannel(controller.foreign);
---
>   return MultiChannel<dynamic>(controller.foreign);
184,185c182,183
< StreamChannel _connectToIframe(String url, int id) {
<   var iframe = IFrameElement();
---
> StreamChannel<dynamic> _connectToIframe(String url, int id) {
>   final IFrameElement iframe = IFrameElement();
187c185,188
<   iframe.src = url;
---
>   iframe
>     ..src = url
>     ..width = '500'
>     ..height = '500';
191,192c192,193
<   var channel = MessageChannel();
<   var controller = StreamChannelController(sync: true);
---
>   final MessageChannel channel = MessageChannel();
>   final StreamChannelController<dynamic> controller = StreamChannelController<dynamic>(sync: true);
196c197
<   var readyCompleter = Completer();
---
>   final Completer<dynamic> readyCompleter = Completer<dynamic>();
198c199
<   var subscriptions = <StreamSubscription>[];
---
>   final List<StreamSubscription<dynamic>> subscriptions = <StreamSubscription<dynamic>>[];
201c202
<   subscriptions.add(window.onMessage.listen((message) {
---
>   subscriptions.add(window.onMessage.listen((dynamic message) {
206c207,209
<     if (message.origin != window.location.origin) return;
---
>     if (message.origin != window.location.origin) {
>       return;
>     }
208,210c211,213
<     // TODO(nweiz): Stop manually checking href here once issue 22554 is
<     // fixed.
<     if (message.data['href'] != iframe.src) return;
---
>     if (message.data['href'] != iframe.src) {
>       return;
>     }
217,218c220
<       iframe.contentWindow
<           .postMessage('port', window.location.origin, [channel.port2]);
---
>       iframe.contentWindow.postMessage('port', window.location.origin, <MessagePort>[channel.port2]);
227c229
<   subscriptions.add(channel.port1.onMessage.listen((message) {
---
>   subscriptions.add(channel.port1.onMessage.listen((dynamic message) {
231c233
<   subscriptions.add(controller.local.stream.listen((message) async {
---
>   subscriptions.add(controller.local.stream.listen((dynamic message) async {
233d234
< 

I think this initial diff is mainly adapting to flutter's style - adding redundant types, requiring final, and some reformatting. Since the initial copy the implementations have diverged some.

See dart-lang/test#2065

Multiple copies of the host and iframe side implementations have been
updated, but this copy of `host.dart` was missed. Apply some of the
changes from the linked test issue to this copy.

- Add `MessageEventSource` and `MessageEventSourceLocation` interop
  classes. The frame side communication no longer includes an `href`
  field in the map, read it through `message.source.location`.
- Move the `DomMessageChannel` initiation into the handler for the
  `{'ready': true}` event. This removes the need for the
  `readyCompleter` since we do not start forwarding messages until the
  port is ready for use.
- Add handling for the new pattern, when the iframe sends a message with
  the string `'port'` instead of a Map.
@natebosch
Copy link
Contributor Author

@yjbanov - I cannot understand this failure or how it might be related to this change.

Have you seen failures that look like this before? It looks related to compiling for AOT?

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8767306603658259521/+/u/run_test.dart_for_web_tests_shard_and_subshard_6/test_stdout

@natebosch natebosch marked this pull request as ready for review October 20, 2023 22:46
@natebosch
Copy link
Contributor Author

Hmm, maybe I'll merge this back with #46592 since it looks like it would take even more steps to separate code changes from the package roll.

@natebosch natebosch closed this Oct 20, 2023
@natebosch natebosch deleted the latest-test branch October 20, 2023 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant