[webkit-changes] [WebKit/WebKit] b00c01: [SwiftUI] Custom `NavigationDeciding` implementati...

Richard Robinson noreply at github.com
Sun Feb 23 11:23:37 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b00c01c1d451d2b7c71cab53d0c0d0220e10e857
      https://github.com/WebKit/WebKit/commit/b00c01c1d451d2b7c71cab53d0c0d0220e10e857
  Author: Richard Robinson <richard_robinson2 at apple.com>
  Date:   2025-02-23 (Sun, 23 Feb 2025)

  Changed paths:
    M Source/WebKit/UIProcess/API/Swift/WKNavigationDelegateAdapter.swift

  Log Message:
  -----------
  [SwiftUI] Custom `NavigationDeciding` implementations have no effect
https://bugs.webkit.org/show_bug.cgi?id=288306
rdar://145390836

Reviewed by Abrar Rahman Protyasha.

Consider the following simplified code:

```
protocol P {
    mutating func f() -> Int
}

extension P {
    func f() -> Int {
        1
    }
}

struct CustomP: P {
    func f() -> Int {
        2
    }
}

class C {
    let p: any P

    init(_ p: any P) {
        self.p = p
    }

    func proxyF() -> Int {
        p.f()
    }
}

let c = C(CustomP())
print(c.proxyF())
```

This results in `1` being printed, since the `CustomP` implementation of `f` isn't used because it implements the `f` requirement
of `P`, which is `mutating`, and therefore isn't allowed to be used with non-mutable value types. And so instead, the implementation
of `f` inside the `extension P` is used instead since that one is considered a separate function entirely, and therefore does not
implement the protocol requirement.

Because 290468 at main changed the NavigationDeciding protocol functions to become `mutating`, and since `WKNavigationDelegateAdapter`
was using `let navigationDecider`, this subtle behavior difference was introduced, resulting in the default implementations always
being used.

Fix by using `var` instead of `let`, so that the mutating protocol requirement implementations in the custom deciders can actually be used.

* Source/WebKit/UIProcess/API/Swift/WKNavigationDelegateAdapter.swift:
(WKNavigationDelegateAdapter.navigationDecider):

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



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list