-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
@tracked Query Params doesn't update the URL #18282
Comments
So I believe the issue here is that QPs are updated with synchronous observers, and I've thought about a couple of solutions to this problem:
I think option 2 makes sense, but we could also go with option 1, assuming we deprecate sync observers very soon. |
For the bug fix, can't we just refactor QPs to not use observers? We have the information available to use at instantiation time, we can do whatever we need to add setters, etc. For the medium term (next release or two), we may be able to RFC a |
This would be a pretty major refactor, and I'm not sure if it would be possible to do with the current QP semantics. The issue is that observers are used to keep QP values in sync with a cache of the values, and this cache is used to then setup the controller when the route reactivates. This cache I believe will also restore values based on dynamic segments of a given route, so there could be multiple values cached per-route. We may be able to update these caches just before a transition, but like I said, I think this would be a pretty major refactor. Forcing a flush of async observers would probably be a better intermediate solution while we're in beta.
I'd rather avoid doing this, as we already have a QP redesign API we're working on that is much more minimal and wouldn't require any annotations/declarations on either the route or the controller. |
@chancancode / @pzuraq - I recall seeing this be discussed in the |
There are two options we discussed:
I think 2 is the most minimal option, and will confirm whether or not this issue is caused by this. I'm still not sure what to do in the general case for sync observers that are attempting to watch tracked properties. |
I also walked into this and used import Controller from '@ember/controller';
import { action, set } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
queryParams = ['count'];
@tracked count = 0;
counter = 0;
@action incrementTracked() {
this.counter++;
set(this, 'count', this.counter);
}
} |
@pzuraq I don't consider #2 to be the more minimal option. #1 is much more targeted, and I can't see any problem with it. In particular, changing the The code in question is here: https://github.com/emberjs/ember.js/blob/master/packages/@ember/-internals/routing/lib/system/route.ts#L1996 |
The solution for #1 isn't to just replace observed properties with tracked properties. It would be to add a completely new setter on top of tracked properties, that wraps the tracked property setter. We can't utilize autotracking here without a major refactor of the router, which is why making observers work as before would be a much smaller change overall. Edit: That said, if anyone wants to write the code for that setter wrapping logic, I'd say go for it, it's not a massive change. The observer flushing logic could just be copied over directly from the commit before we landed async observers, and it would be maybe 4 lines of code total, which is why I believe it would be more minimal. |
Are async observers expected to work with |
Yes, they were spec'd to interop, and they work correctly today |
Are you saying that QP getters can't work? How would you express a QP getter? |
Currently, no, they definitely cannot, without |
Could we poll the QPs instead of flushing all sync observers? Where's the relevant code? |
I feel like there should be a way to do this without observers at all, because the logic that is run in them is just to update the cache. Like, we should be able to update that cache just before we leave a route, so there shouldn't be a need to update it every single time its value updates. It's just a bit of a larger refactor, and I haven't had time to dig into the way the router works, so there are some unknowns. I think it may be something we have to do though if we really want to fix this, especially for undecorated getters 😕 |
Fixed by #18358 (for now) |
Only
incrementSet
works here.The text was updated successfully, but these errors were encountered: