Skip to content
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

Duplicated/invalid actions are received when tab view appear #2

Open
darrarski opened this issue Apr 12, 2021 · 1 comment · May be fixed by #3
Open

Duplicated/invalid actions are received when tab view appear #2

darrarski opened this issue Apr 12, 2021 · 1 comment · May be fixed by #3
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@darrarski
Copy link
Owner

darrarski commented Apr 12, 2021

Description

Reported by @saroar in a comment to another issue.

Steps to reproduce

  1. Add onAppear actions to each component.
  2. Send the onAppear action to the ViewStore inside .onAppear(perform:) modifier in each view.
  3. In each of the reducers, just return .none effect when onAppear action is received.
  4. Run the app and randomly switch tabs.

Expected behavior

  1. Whenever tab is switched, onAppear action of the currently selected tab's component should be received.

Actual behavior

  1. Sometimes wrong onAppear action is received, for example when switching from "Color" to "Shape" tab, instead of single ShapeAction.onAppear, two actions are received: ShapeAction.onAppear and then PreviewAction.onAppear.

Testing notes

The issue occurs only when action is sent to the ViewStore in .onAppear(perform:) modifier. When not sending the action in the closure (but for example just printing something to the console) - everything is working as expected.

@darrarski darrarski added the bug Something isn't working label Apr 12, 2021
@darrarski darrarski self-assigned this Apr 12, 2021
@darrarski darrarski mentioned this issue Apr 12, 2021
@darrarski darrarski linked a pull request Apr 12, 2021 that will close this issue
@darrarski darrarski linked a pull request Apr 12, 2021 that will close this issue
@darrarski darrarski added the help wanted Extra attention is needed label Apr 12, 2021
@darrarski
Copy link
Owner Author

This is a strange issue indeed. It's hard to tell if this is a bug in SwiftUI or a problem with ComposableArchitecture. It seems to be only reproducible when action is sent inside .onAppear(perform:) modifier.

As a workaround (which I can confirm solves the problem) we can move .onAppear(perform:) from the body of a view presented in a tab to the place where it's created. It's not an ideal solution, though. I applied the workaround in #3 in this commit: 48e36d1.

@darrarski darrarski changed the title Duplicated/invalid actions are received when tab views appears Duplicated/invalid actions are received when tab view appear Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant