Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

NavigationStack(path:root:destination:) not rendering root view when scoping the store into a new one. #2957

Closed
3 tasks done
danielsan22 opened this issue Mar 31, 2024 · 2 comments
Labels
bug Something isn't working due to a bug in the library.

Comments

@danielsan22
Copy link

Description

Hi all, first of all, great work on this library!

I wanted to implement navigation within the app I'm working on to learn/practice more about TCA, I implemented a new feature RootFeature that will hold the state of the stack, and added there the initial state of my top most feature to then scope it out and have it as the root of the NavigationStack(path:root:destination) view.
But when building the main feature using the RootFeature I only get a white screen, that does loads and sends the initial .onTask action but never updates anything else, even when printing the changes on the reducer I can see that there is no change on the state and no other action is sent even tho the .onTask sends an array of data.

However, if I create a new store and pass it to the MainView inside the root parameter of the NavigationStack I do get the screen displaying and all the functionality that I expect, but I haven't found a way of comunicating to the parent RootFeature and get the actions that then will trigger the navigation I have defined on the RootFeature.

I am unsure if this is something that I should be doing or not or instead focus on having all the navigation logic directly inside the feature that will be the "true" root feature, but I like having my features a bit more isolated, thats why having the RootFeature take care of all the details of the other screens/features makes sense to me, it is also how I understood the docs since the examples use a simple NavigationLink as root (which to my app does not make sense to do that).

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The NavigationStack's root view can be created using a scoped version of the RootFeature's store and renders and works with all the defined actions.

Actual behavior

The NavigationStack's root view is not displayed and the console prints out no changes to the sate even when they are hard-coded as when the view loads.

Steps to reproduce

I have created a brand new project and recreated the issue there.

The Composable Architecture version information

1.9.2

Destination operating system

iOS 17

Xcode version information

15.0

Swift Compiler version information

swift-driver version: 1.82.2 Apple Swift version 5.9 (swiftlang-5.9.0.114.10 clang-1500.0.29.1)
Target: arm64-apple-macosx13.0
@danielsan22 danielsan22 added the bug Something isn't working due to a bug in the library. label Mar 31, 2024
@mbrandonw
Copy link
Member

Hi @danielsan22, the problem is in the body of the RootFeature:

https://github.com/danielsan22/NavStackReproduction/blob/973142a5ef7a4e7153d7fbe2a6ef97bf7d315256/NavStackReproduction/RootView.swift#L19-L31

You aren't composing the MainFeature reducer into this at all. It should be more like this:

 var body: some ReducerOf<Self> {
+    Scope(state: \.cardsSets, action: \.cardsSets) {
+      MainFeature()
+    }
     Reduce { _, action in
         switch action {
         case .path:
             return .none
         case .cardSets:
             return .none
         }
     }
     .forEach(\.path, action: \.path) {
         Path()
     }
 }

@mbrandonw
Copy link
Member

Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue to discuss over there.

@pointfreeco pointfreeco locked and limited conversation to collaborators Mar 31, 2024
@mbrandonw mbrandonw converted this issue into discussion #2958 Mar 31, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working due to a bug in the library.
Projects
None yet
Development

No branches or pull requests

2 participants