Bug introduced in 11.3 or earlier, and persisting through 12.0
CASE:4372001 confirmed
I am running into an issue trying to improve the performance of my user interface by moving as much of the state handling into the front-end as possible. It appears as though nesting EventHandler
forces the kernel to be called, no matter what the action to be performed is.
The following examples illustrate what I am trying to achieve, and how it fails:
Single EventHandler, front-end-only state
This one works as intended: Clicking on the number toggles between 1
and 2
, and no front-end <-> kernel communication occurs (verified with LinkSnooper)
DynamicModule[
{open},
EventHandler[
PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
{
"MouseClicked" :> FEPrivate`Set[open, FEPrivate`Not@open]
}
]
]
Nested EventHandler, front-end-only state
This is the problematic case: Despite the PassEventsDown -> True
, this doesn't work.
EventHandler[
DynamicModule[
{open},
EventHandler[
PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
{"MouseClicked" :> FEPrivate`Set[open, FEPrivate`Not@open]}
]
],
{"MouseClicked" :> True},
PassEventsDown -> True
]
Nested EventHandler, kernel-side state
This one works as expected, but needs to call the kernel:
EventHandler[
DynamicModule[
{open},
EventHandler[
PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
{"MouseClicked" :> (open = ! open)}
]
],
{"MouseClicked" :> True},
PassEventsDown -> True
]
Nested EventHandler, front-end-only state, using FE`Evaluate
This one is thanks to @Kuba, who noticed that the event action is sent to the kernel even though it shouldn't be. This means that adding FE`Evaluate
can be used to make it work. The problem is of course that this still calls the kernel.
EventHandler[
DynamicModule[
{open},
EventHandler[
PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
{"MouseClicked" :> FE`Evaluate@FEPrivate`Set[open, FEPrivate`Not@open]}
]
],
{"MouseClicked" :> True},
PassEventsDown -> True
]
Question
Since WRI support already confirmed that this is a bug, I am only looking for a possible work-around. Is there any way to get nested, clickable boxes that work entirely in the front-end?