[web] Fix HtmlViewEmbedder.dispose (flutter/engine#50482)

Fix a `Concurrent modification during iteration` in the `dispose` method of the HtmlViewEmbedder.

### Issues

Fixes https://github.com/flutter/flutter/issues/143193

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
David Iglesias
2024-02-09 11:11:48 -08:00
committed by GitHub
parent e6f37afc69
commit 8a8ce3b20f
2 changed files with 38 additions and 1 deletions

View File

@@ -658,7 +658,7 @@ class HtmlViewEmbedder {
/// Disposes the state of this view embedder.
void dispose() {
disposeViews(_viewClipChains.keys);
disposeViews(_viewClipChains.keys.toList());
_context = EmbedderFrameContext();
_currentCompositionParams.clear();
debugCleanupSvgClipPaths();

View File

@@ -974,6 +974,43 @@ void testMain() {
}
});
});
test('can dispose without crashing', () async {
ui_web.platformViewRegistry.registerViewFactory(
'test-view',
(int viewId) =>
createDomHTMLDivElement()..className = 'platform-view',
isVisible: false);
await createPlatformView(0, 'test-view');
await createPlatformView(1, 'test-view');
await createPlatformView(2, 'test-view');
final LayerSceneBuilder sb = LayerSceneBuilder()
..pushOffset(0, 0)
..addPlatformView(0, width: 10, height: 10)
..addPlatformView(1, width: 10, height: 10)
..addPlatformView(2, width: 10, height: 10)
..pop();
await renderScene(sb.build());
_expectSceneMatches(<_EmbeddedViewMarker>[
_overlay,
_platformView,
_platformView,
_platformView,
]);
expect(() {
final HtmlViewEmbedder embedder =
(renderer as CanvasKitRenderer)
.debugGetRasterizerForView(implicitView)!
.viewEmbedder;
// The following line used to cause a "Concurrent modification during iteration"
embedder.dispose();
}, returnsNormally);
});
}
// Used to test that the platform views and overlays are in the correct order in