jovotech/jovo-framework

@PrioritizedOverUnhandled() on not global handler gets ignored

acerbisgianluca opened this issue · 3 comments

I'm submitting a...

  • Bug report
  • Feature request
  • Documentation issue or request
  • Other... Please describe:

Expected Behavior

The docs says that handlers from all the components that are part of the $state stack and global handlers from all root components are selected for the matches array.
Now, I've ComponentA which has a global handler and a "local" one (both of them have @PrioritizedOverUnhandled() annotation) and ComponentB which has a local handler and UNHANDLED. Let's assume that the current $state stack is [ComponentA, ComponentB], so now I'm inside ComponentB.
If I invoke the intent handled by the global handler in ComponentA, the handler is correctly triggered. The problem is that if I invoke the other intent, the "local" handler isn't triggered and the request gets handled by the UNHANDLED in ComponentB.
From the docs, I assume that the local handler in ComponentA should be in the matches array as well, since ComponentA is in the current $state stack. But apparently, even if the local handler has @PrioritizedOverUnhandled() annotation, it isn't considered by the router.

Current Behavior

You can see current behaviour in this repo vocalime-base/jovo-4-router-issue.

Just run npm test.

Your Environment

  • Jovo Framework version used: 4.2.20

Note 1: it works if I remove ComponentB from the root components and add it to the subcomponents of ComponentA. In order to test this solution, change the $state stack to:

"state": [
                {
                    "component": "ComponentA"
                },
                {
                    "component": "ComponentA.ComponentB"
                }
            ]

Now I'm wondering if $state stack in "Handlers from all components that are part of the $state stack" refers to the entire $state array or only to the name of the last component of the array (in the example above: "ComponentA.ComponentB").

Note 2: The docs states these 2 points:

  • Handlers from all components that are part of the $state stack
  • Global handlers from all root components

I think that IntentA works fine because of the second condition, since it's a global handler and ComponentA is a root component. So the problem should be caused by something wrong with @PrioritizedOverUnhandled() and the first condition.

Thank you for the example code. I could reproduce it and there's definitely something wrong with the routing. We'll investigate

This was fixed by @palle-k. Thank you! 🎉🎉🎉