Repository navigation
fix(ios): classify asset responses using resolved file URL - #8741
Open
basnijholt wants to merge 1 commit into
Open
basnijholt wants to merge 1 commit into
basnijholt wants to merge 1 commit into
Conversation
Assisted-by: MindRoom DevAgent:google/gemini-4-neon <https://github.com/mindroom-ai/mindroom>
This branch has not been deployed
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.
Description
Update
WebViewAssetHandler.webView(_:start:)to classify responses using the resolvedfileUrlwhile preserving thecordova.jsstub and extensionless-file fallback:cordova.jsstub when the last path component of the request iscordova.js(url.lastPathComponent == "cordova.js") rather thanstringToLoad.contains("cordova.js"), keepingurl.pathExtension(js) so root and nestedcordova.jsrequests return an empty JavaScript response even when a custom router falls back toindex.html. Substring-only paths (such ascordova.jsonormycordova.js) are now served instead of returning empty.fileUrl.pathExtensionwhen non-empty and fall back tourl.pathExtensionwhen the resolved file has no extension, for bothmimeTypeForExtensionandisMediaExtension(data loading andURLResponsevsHTTPURLResponse).Added regression tests in
ios/Tests/CapacitorTests/WebViewAssetHandlerTests.swift.Change Type
Rationale / Problems Fixed
When an app provides a custom
Routerthat maps dot-suffixed SPA routes (for example/explore/example.com,/watch/clip.mp4, or/explore/mycordova.js) toindex.html,WebViewAssetHandlercurrently inspects the request URL instead of the resolved file:text/html.URLResponseinstead ofHTTPURLResponse."cordova.js"skips reading the resolved file and returns empty bytes.This PR changes only the iOS asset handler.
No related issue: found while using a custom iOS
Routerwith dot-suffixed SPA routes.Tests or Reproductions
Added
ios/Tests/CapacitorTests/WebViewAssetHandlerTests.swiftcovering:Routermapping/explore/example.com,/watch/clip.mp4, and/explore/mycordova.jstoindex.html(verifiestext/html,HTTPURLResponse, and fullindex.htmlbytes)./cordova.jsreturning an empty JavaScript stub (JS MIME,HTTPURLResponse) both when the router falls back toindex.htmland when a non-emptycordova.jsfile exists on disk./room/cordova.jsreturning the empty JavaScript stub (JS MIME,HTTPURLResponse).Routermapping/vendor/runtime.jsto a real file namedcordova.jsserving that file's contents with JS MIME.Routermapping/app.jsand/clip.mp4to extensionless files falling back tourl.pathExtensionfor MIME type and media response handling..js) and media (.mp4) files preserving their bytes, MIME types, and response classes.Built and tested on macOS (Xcode 26.6, iPhone 17 / iOS 26.5 simulator):
xcodebuild build -scheme Capacitor-Package -destination 'generic/platform=iOS Simulator'—BUILD SUCCEEDEDxcodebuild test -scheme Capacitor-Package -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.5' -collect-test-diagnostics never—TEST SUCCEEDED:CapacitorObjCTests.xctest: 6/6 passedCapacitorTests.xctest(XCTest): 24/24 passed (including 7/7 inWebViewAssetHandlerTests)Not run locally:
npm run swiftlint -- lint(unverified; CI will check).Screenshots / Media
N/A
Platforms Affected
Notes / Comments
next.google/gemini-4-neon); thexcodebuild buildandxcodebuild testcommands listed under Tests were run on macOS (Xcode 26.6, iPhone 17 / iOS 26.5 simulator); SwiftLint was not run locally.