Fix: alert action not routed to reducer in MultipleDestinations tutorial - #3959
Open
carlosypunto wants to merge 1 commit into
Open
Fix: alert action not routed to reducer in MultipleDestinations tutorial#3959carlosypunto wants to merge 1 commit into
carlosypunto wants to merge 1 commit into
Conversation
The tutorial's alert modifier was calling `.alert(_ state:)` with a
single argument, which resolves to the overload in SwiftUINavigation
that has been deprecated (deprecated after swift-navigation 2.7.0)
because it silently discards the alert's button action:
public func alert<Value>(_ state: Binding<AlertState<Value>?>) -> some View {
alert(state) { _ in }
}
Since TCA 1.25's enum-scope API returns direct access to the alert
state (not wrapped in a `Store`) for non-reducer destination cases,
callers must supply an explicit trailing action handler to route the
tapped button's action back into the store. Without it, the action is
dropped and never reaches the reducer.
This adds the explicit handler, forwarding the alert action through
`store.send(.destination(.presented(.alert(action))))`, which resolves
the deprecation warning and makes button taps in the alert actually
reach the reducer.
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.
What
02-02-02-code-0014.swiftin the "Multiple destinations" tutorial step presents the alert like this:This single-argument call resolves to the
alert(_ state:)overload in swift-navigation that's deprecated as of 2.7.0, since it discards the button action instead of forwarding it:As a result, tapping a button in the alert never reaches the reducer — and building the tutorial's code as written produces this deprecation warning in Xcode:
Why this happens
With the enum-scope API introduced in TCA 1.25, scoping into a non-reducer case of a destination enum (like
.alert) now returns direct access to the state (a plainBinding<AlertState<Value>?>) rather than aStore-wrapped binding. That means the action handler is no longer wired automatically and must be supplied explicitly.Suggested fix
I confirmed locally that the current tutorial code compiles with the deprecation warning above and drops the alert's action, while this change compiles cleanly and correctly routes the action to the reducer.
Note
I'm learning TCA, so please let me know if there's a more idiomatic way to route the action here that I'm missing — happy to update the PR.