Skip to content

Conversation

@markmur
Copy link
Contributor

@markmur markmur commented Dec 17, 2025

What changes are you making?


Before you merge

Important

Releasing a new version of the kit?

Releasing a new major version?

  • I have bumped the version number in the README.

Tip

See the Contributing documentation for instructions on how to publish a new version of the library.

Wire up the CheckoutSubmitStartEvent to the SwiftUI modifier pattern,
allowing SwiftUI apps to handle checkout submit events via:

.onSubmitStart { event in
    // Handle submit start
    event.respondWith(payload: response)
}
@markmur markmur self-assigned this Dec 17, 2025
Adds testOnSubmitStart to verify the SwiftUI modifier correctly
wires up the CheckoutSubmitStartEvent to the delegate wrapper.
@markmur markmur force-pushed the prototype/onSubmitStart-swiftui branch from 51af86c to 4f32f72 Compare December 17, 2025 10:44
@markmur markmur force-pushed the prototype/checkout.submit branch from 56d6680 to 10fa83c Compare December 17, 2025 10:44
// MARK: - Encodable Conformance

extension CheckoutSubmitRequest {
public func encode(to encoder: Encoder) throws {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be declared in the OutboundRPCRequest extension?
Using the associatedType ResponsePayload generic you should have access to the Codable


// Cancel any pending outbound requests to prevent continuation leaks
Task { [pendingRequests] in
await pendingRequests.cancelAll()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if this should also be cleared if URL changes? I think load could be called multiple times on the same Webview

// Get the raw response data from the pending request
let responseData: Data = try await withCheckedThrowingContinuation { continuation in
Task {
await pendingRequests.register(id: request.id, continuation: continuation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have a race condition with CheckoutBridge.sendRequest?
Could all of this go in an async context?


Task {
do {
let responseData = try JSONEncoder().encode(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A back and forth happening here on these response types
userContentController( _: WKUserContentController, didReceive message: WKScriptMessage ) Does the following

  1. Calls CheckoutBridge.decode
  2. Calls handleBridgeEvent
    So the entry point for these responses is decode to envelope, then encode back to data, and we complete the pendingRequests with Data

Possible optimisation opportunity

@kiftio
Copy link
Contributor

kiftio commented Dec 17, 2025

I suppose we're not exposing this in the imperative API. Which feels like it's probably OK?

@kieran-osgood-shopify
Copy link
Contributor

Definitely on the right track
Think this shows theres now a fairly considerable more indirection and conflation between the event entrypoints and processing of those events
Would be good to see how we can split those succinctly?

@markmur markmur force-pushed the prototype/onSubmitStart-swiftui branch from ca6ed8f to f492e4a Compare December 17, 2025 13:50
Base automatically changed from prototype/onSubmitStart-swiftui to prototype/development December 17, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants