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
fix(router): resolve guard observables on the first emit #10412
Conversation
c7c90ab
to
fc9d1b8
Compare
Could you rebase the PR, so it can be merged into master? |
dc255d1
to
dc9f542
Compare
dc9f542
to
c6d645f
Compare
@vsavkin Done. Failing tests are unrelated, although I think router specs are not included in the passing ones, I'd double check that. |
Is there a pattern this implementation has in-mind, on how to disconnect when navigating away? |
@syndicatedshannon I don't have any idea what you're saying -- disconnect what? |
@awerlang I assume this causes a connection or subscription to the observable being resolved? When is it disconnected or unsubscribed? If this implementation unsubscribes immediately, e.g. by simply calling "first", then if I understand correctly this is a breaking change and I would think it is also undesired behavior. |
To clarify, here is a portion of our current implementation. |
By returning an observable, you understand the framework needs to subscribe to it and later unsubscribe. Before this PR, users wouldn't call |
How do you guard without subscribing? |
I can't see where this line of reasoning would lead us to. You haven't explained how this PR presents |
I'd be glad to clarify the undesired behavior, if any, if I understand the behavior. Does the current implementation subscribe, retrieve the first item, and then unsubscribe? |
The expected behavior of an observable is that is a stream of data. That's what differentiates it from a promise. It could be argued that a resolve on an observable should, by default, wait for the last item. I desire a more nuanced solution than that, but I can understand the difficulty in implementing it, and so I accept this "wait for completion/last item" behavior. But keeping the expected behavior mentioned above in mind, I don't think it can be reasonably argued that a resolve on an observable should wait for the first item and then hide all access to future items. I understand this may work well for an observable that has only one item. This is what we might see from a simple HTTP request. But that is simply represented by a promise, and missing (half of) the expected value of an observable. Subscribing, retrieving the first value, and unsubscribing, requires the consumer to subscribe a second time in the controller, creating a duplicate network request. |
Current approach lets user code use
Oh wait! Did I go too far and implemented this for Resolve too? I meant this PR for OnActivate/OnDeactivate only. Can you confirm this?
This is valid for resolved data you want to access inside the component. Not for OnActivate/Deactivate data. |
Ahhh, I see! I don't know, I think I saw resolve linkage, but then I was expecting to see it, because of a comment someone left me on my other issue. Let me verify. |
Ugh, I'm going to need some time to clear my head with this. I've been working on 2.x for over a year and been through a lot of OnActivate implementations - it's messing with my head. I don't initially see any relation to my resolve issue. I don't see immediately how expected behavior would be different for OnActivate "resolve", but since you pointed out the distinction I'm sure you are right. Sorry for the misdirect. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
What is the current behavior? (You can also link to an open issue here)
#9613
What is the new behavior?
On the first received value from an observable, decide to continue or cancel (de)activation. Waiting for completion is not required.
Does this PR introduce a breaking change? (check one with "x")
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information:
I believe this isn't a breaking change, even though the behavior is changed (accepting more than one value in the stream), because this wasn't properly documented. Also, I think is much more convenient to not require the observable to complete.