# strange error in nested manipulate

Below is an illustration of the problem.

 a={1->{{8,9},{8,22}},2->{{8,3,19},{8,14,19}}};
b={1->{1,2},2->{1,2,3}};
Manipulate[
Manipulate[
{case,item/.a,ControlType->Setter}],
{item,Keys@a}]


If you run the above code, it will show this

then if you switch to item 2, you got an Thread error like this

The error says, Thread encounters unequal length objects. However, the output of Manipulate is actually right! I don't get it, why there is an intermediate error? How to get rid of this error?

• Since the output is okay, you could use Off[Thread::tdlen] as a very, very nasty hack. Lateron, you can reactive these error messages with On[Thread::tdlen]... – Henrik Schumacher Feb 24 '18 at 11:09
• @HenrikSchumacher Thanks! Indeed, I can also mask it with Quiet. But wait for an explanation and a formal way to get rid of it : ) – matheorem Feb 24 '18 at 11:39

It seems to be a question of timing. The code segment Thread[case -> (item /. b)] is being updated before the inside Manipulate. This can happen, I suppose, because the Thread[..] segment is wrapped in Dynamic[] and is dependent on the symbols {case, item, a, b}. When Thread[..] is updated, item has changed, but case has not yet been updated. This causes the mismatch in lengths.

The fix would be to control the dependencies with TrackedSymbols and/or Dynamic/Refresh. Both of the following eliminate the problem (adjust to suit desired dependencies):

Manipulate[
Manipulate[
{case, item /. a, ControlType -> Setter},
TrackedSymbols :> True],
{item, Keys@a}]

Manipulate[
Dynamic@Refresh[
Manipulate[

• Hi, Michael E2. Thank you very much! +1 for solving the issue. But I don't quite understand TrackedSymbols. For example, in the first example, TrackedSymbols :> Manipulate, what does this Manipulate refer to? The outer manipulate or inner manipulate? And I don't understand why Manipulate can track itself? – matheorem Feb 24 '18 at 15:16
• @matheorem TrackedSymbols :> Manipulate apparently is now supposed to be TrackedSymbols :> True: Both track the symbols in the controls in the Manipulate, so they would be the same as TrackedSymbols :> {case} in example. I learned the first one in a class when V6 came out. – Michael E2 Feb 24 '18 at 15:30