-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
[Bug]: v3 - Service callbacks onAccept & onReject are not called unless both are defined #593
Comments
Hi @techfg, to me the current behavior is the more appropriate one. A service can be enabled/accepted only if it is (now) disabled/rejected.
|
Hi @orestbida - Thanks for reviewing! I believe the current behavior would allow a service to be enabled/accepted & disabled/rejected multiple times in a session , possibly I'm misunderstanding? Possibly you're referring to the scripts executing themselves vs. the callbacks? For example, if you define onAccept & onReject callbacks, and then toggle a service multiple times back and forth, onAccept & onReject are called for each toggle (see here). I believe this is expected behavior. The issue I noticed is that if one (or the other) is not defined, then the defined callback is not invoked on every toggle to its respective state. A use case would be Google Tag Manager with Consent Mode enabled - A user could accept or reject cookies multiple times within a session. On each transition the corresponding consent update needs to be sent to GTM. |
Yes, services are meant to be disabled/enabled multiple times in the current session, but only if there is an implementation of the 2 callbacks, that (should) do something.
This is what I mean: if the car is already running, you can't "re run/start" it again, unless you turn it off first. If the car is already off, you can't turn it off again. By not implementing one of the 2 callback functions, you are (likely) not respecting the user's choice.
I agree, but you would achieve this with both callbacks implemented, or am I missing something? |
Agreed, believe we are on the same page here, in theory, you should be using both or none, not one or the other (although I guess there could be situations where you only want to do certain things in one or the other case). The main concern I saw was tracking internal state If so, possibly just the typings need to be updated so that someone can't define one and not the other (or just the docs updated to making it clear on usage)? Thanks! |
Yes, the Every property starting with |
Understood Understood all your comments and think it really comes down to how onAccept/onReject are defined/expected to be used and of course, this is up to you. If current behavior is maintained, only thing I would recommend is changing the typings so that the consumer knows that neither or both should be defined to get expected behavior - the typings allow one or the other (which is how I stumbled upon this in the first place when testing our v3 :)). Possibly instead of: service: {
onAccept?: () => void
onReject?: () => void
} it could be: service: {
callbacks?: {
onAccept: () => void
onReject: () => void
} |
They were left as optional because you can define the onAccept/onReject behavior using I agree with you that the proposed change would make things clearer, but at the same time it's also a breaking change that I'd like to avoid. We could avoid the breaking change, by allowing both ways, but that would clutter the configuration and potentially confuse users. I consider v3 stable; the only thing preventing me from officially announcing v3 is the state of the playground page, it needs a few extra touches. |
I hear you :) Interesting about the script tags and the run on disable ( |
Scripts configured as services follow the same logic as internal services: If user accepts the service => enable the related "onAccept" script. There is however 1 crucial difference between services implemented as scripts, and those implemented through the config. object: This is a design choice inherited from v2, and was kept the same in v3 so that users coming from v2 would "feel at home". Script tags are generally adopted by beginners, since they are the simplest most common way of handling code. Services were introduced as a bonus feature, in a later moment, as this level of granularity/control was not a requirement for a compliant consent solution. |
All makes sense now, appreciate you providing the details/background. I updated #594 reverting the scripts code back to the previous and updating the tests to align with the expected behavior that you've described. Will leave to decide to close out the PR or merge if you think the tests are helpful. Thanks again for your work! |
Expected Behavior
If onAccept and/or onReject are defined, they should always be called when the service enters the respective state
Current Behavior
service._enabled
does not get set back to false)service._enabled
does not get set to true)Steps to reproduce
Proposed fix or additional info.
Remove the check
isFunction
checks for onAccept/onReject to within the corresponding if...else blocksVersion
3
On which browser do you see the issue?
Firefox, Chrome, Microsoft Edge
The text was updated successfully, but these errors were encountered: