Repository navigation
Create the preview's browser at its real size, so it never comes up blank - #15
Merged
Merged
Conversation
… up blank. The preview sometimes came up blank under a toolbar reading "Running", and a hot restart brought the app back. The app was running the whole time — in a browser one pixel wide. A CEF browser starts at 1x1 and scale 1 and was only sized by the first setSize, once its surface was mounted. On a Retina Mac that first size also moves the scale from 1 to 2, and WasResized() does not deliver a scale change to a page that is already rendering: the page takes the new scale and keeps its old size until its next navigation. Usually the size won the race with the renderer. On a project switch it always lost, because the profile is cleared and the page reloaded before the surface is built. - WebViewController.initialize takes the initial size and device pixel ratio, and the fork creates the browser with them. - PreviewPane passes the phone viewport, or on desktop the room under its header. - changeSize calls NotifyScreenInfoChanged() before WasResized() when the scale changes, so a later scale change lands too. Verified in a debug build with two projects: first open, project switch, Full Restart, and phone, landscape and desktop modes. The Windows side of the shared plugin code is not built or tested here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Sometimes a project starts and the preview stays blank while the toolbar says "Running". Pressing Hot Restart brings the app up.
The app was running the whole time, in a browser one pixel wide:
setSize, once the preview surface was mounted.WasResized()does not deliver a scale change to a page that is already rendering: the page takes the new scale and keeps its old size until its next navigation. That is why Hot Restart, which reloads the page, cured it._ensureWebViewclears the profile and reloads before the surface is built, about four seconds later.Measured in the stuck page:
innerWidth1,devicePixelRatio2,flutter-view1x1.It was not the Flutter tool, DWDS or the runner. In Chrome, reloading at every point of the first connection, hot-restarting mid-load and calling
main()early all still brought the app up.The fix
WebViewController.initializetakesinitialSizeanddevicePixelRatio, and the fork creates the browser with them.GetViewRectandGetScreenInfoanswer from them whileCreateBrowserSyncis still running.PreviewPanepasses the phone viewport, or on desktop the room under its header (previewInitialSurfaceSize).changeSizecallsNotifyScreenInfoChanged()beforeWasResized()when the scale changes, so a later scale change lands too. This half alone already fixed the project switch.AGENTS.mdrecords the cause and corrects the earlier note that said it was not found.Testing
flutter testpasses, including the newtest/preview/preview_initial_surface_test.dart.Not verified:
changeSizechange should cover it, but it was not tested.🤖 Generated with Claude Code