From 5f5882599320f0c2c46c8d9b2fa36312f61117e3 Mon Sep 17 00:00:00 2001 From: John Ryan Date: Wed, 14 Aug 2024 14:38:14 -0700 Subject: [PATCH] Enable --wasm flag for production builds (#3039) * Enable --wasm flag for production builds * Use Future.delayed to ensure that Codemirror refresh is consistent * Use delay to call refresh() in intersection observer, add comment. --- .cloud_build/dart_pad.yaml | 2 +- pkgs/dartpad_ui/lib/editor/editor.dart | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.cloud_build/dart_pad.yaml b/.cloud_build/dart_pad.yaml index 0ef138ac0..64b81d9f8 100644 --- a/.cloud_build/dart_pad.yaml +++ b/.cloud_build/dart_pad.yaml @@ -1,6 +1,6 @@ steps: - name: gcr.io/$PROJECT_ID/flutter:main - args: ['build', 'web'] + args: ['build', 'web', '--wasm'] dir: pkgs/dartpad_ui - name: gcr.io/$PROJECT_ID/firebase args: ['deploy', '--project=$PROJECT_ID', '--only', 'hosting:dartpad'] diff --git a/pkgs/dartpad_ui/lib/editor/editor.dart b/pkgs/dartpad_ui/lib/editor/editor.dart index d06a19ef2..50b918919 100644 --- a/pkgs/dartpad_ui/lib/editor/editor.dart +++ b/pkgs/dartpad_ui/lib/editor/editor.dart @@ -199,7 +199,10 @@ class _EditorWidgetState extends State implements EditorService { // darkmode _updateCodemirrorMode(darkMode); - Timer.run(() => codeMirror!.refresh()); + // Use a longer delay so that the platform view is displayed + // correctly when compiled to Wasm + Future.delayed( + const Duration(milliseconds: 80), () => codeMirror!.refresh()); codeMirror!.on( 'change', @@ -258,7 +261,10 @@ class _EditorWidgetState extends State implements EditorService { for (final entry in entries.toDart) { if (entry.isIntersecting) { observer.unobserve(web.document.body!); - Timer.run(() => codeMirror!.refresh()); + // Use a longer delay so that the platform view is displayed + // correctly when compiled to Wasm + Future.delayed( + const Duration(milliseconds: 80), () => codeMirror!.refresh()); return; } }