Skip to content

[SwiftUI] Cannot load any content if the return value of the loading APIs is discarded #47329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

rr-codes
Copy link
Contributor

@rr-codes rr-codes commented Jun 28, 2025

847b972

[SwiftUI] Cannot load any content if the return value of the loading APIs is discarded
https://bugs.webkit.org/show_bug.cgi?id=295133
rdar://154524118

Reviewed by Aditya Keerthi.

The updated API added in 296486@main added functionality to facilitate cancelling a navigation
if the navigation stream that results from using the loading APIs is cancelled.

However, this had the unintended side effect of always immediately cancelling a navigation
if the return value is discarded, since the stream's lifetime will have ended instantly.

Fix by storing the streams internally like how the continuations are stored so that their lifetime
is tied to the lifetime of the WebPage except if the client explicitly cancels it.

Add a test, and address a FIXME in SwiftBrowser.

* Source/WebKit/UIProcess/API/Swift/WebPage.swift:
(scopedStreams):
(toNavigationSequence(_:)):
* Tools/SwiftBrowser/Source/Views/ContentView.swift:
(ContentView.body):
* Tools/TestWebKitAPI/Tests/WebKit Swift/WebPageNavigationTests.swift:
(WebPageNavigationTests.navigationProceedsAfterDiscardingNavigationStream):

Canonical link: https://commits.webkit.org/296765@main

c6fc542

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@rr-codes rr-codes self-assigned this Jun 28, 2025
@rr-codes rr-codes added the WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore). label Jun 28, 2025
@rr-codes rr-codes added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 28, 2025
…APIs is discarded

https://bugs.webkit.org/show_bug.cgi?id=295133
rdar://154524118

Reviewed by Aditya Keerthi.

The updated API added in 296486@main added functionality to facilitate cancelling a navigation
if the navigation stream that results from using the loading APIs is cancelled.

However, this had the unintended side effect of always immediately cancelling a navigation
if the return value is discarded, since the stream's lifetime will have ended instantly.

Fix by storing the streams internally like how the continuations are stored so that their lifetime
is tied to the lifetime of the WebPage except if the client explicitly cancels it.

Add a test, and address a FIXME in SwiftBrowser.

* Source/WebKit/UIProcess/API/Swift/WebPage.swift:
(scopedStreams):
(toNavigationSequence(_:)):
* Tools/SwiftBrowser/Source/Views/ContentView.swift:
(ContentView.body):
* Tools/TestWebKitAPI/Tests/WebKit Swift/WebPageNavigationTests.swift:
(WebPageNavigationTests.navigationProceedsAfterDiscardingNavigationStream):

Canonical link: https://commits.webkit.org/296765@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/SwiftUI-Cannot-load-any-content-if-the-return-value-of-the-loading-APIs-is-discarded branch from c6fc542 to 847b972 Compare June 28, 2025 02:25
@webkit-commit-queue
Copy link
Collaborator

Committed 296765@main (847b972): https://commits.webkit.org/296765@main

Reviewed commits have been landed. Closing PR #47329 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 847b972 into WebKit:main Jun 28, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebKit Misc. For miscellaneous bugs in the WebKit framework (and not JavaScriptCore or WebCore).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants