Repository navigation
Load the URL of WebView only when it changed - #18
Merged
Merged
Conversation
SwiftUI calls updateUIView/updateNSView on every state change of the surrounding view. WebView loaded its URL in there each time, which threw away pages the user had navigated to and reset the scroll position. The coordinator now remembers the loaded URL and also keeps its parent current, so a changed onOpenExternalURL closure is used.
The tests now call the representable's update method with a web view that records load requests, so they cover the loaded-URL bookkeeping and the delegate and parent updates, not only the comparison. The suite runs on the main actor, which removes the isolation warning.
The helper only wrapped an inequality check and is no longer needed by the tests, which drive the update path directly.
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.
Overview
WebViewcalledwebView.load(…)in everyupdateUIView/updateNSView, i.e. on every state change of the surrounding view. That reset the page the user had navigated to and the scroll position. The coordinator now remembers the loaded URL and loads only when it changed. It also updatesparent, so a newonOpenExternalURLclosure takes effect.Split out of #7.
How this was verified
WebViewTestscall the representable's realupdate(_:coordinator:)with aWKWebViewsubclass that records load requests. Three updates with the same URL load once; a URL change loads the new URL once and updates the coordinator'sparent.mainhas noupdate(_:coordinator:), so for the red run the URL check was removed, which ismain's behavior (always load):Green, this branch: