Derivative of Sort

I want to calculate gradient of Sort[{x1,x2,x3,x4}] but it seems like I’m getting a wrong answer. Specifically Plot[Sort[{2, 1, x, 10}][[4]], {x, -20, 20}] gives me

enter image description here

while D[Sort[{2,1,x,10}],x] returns {0,0,0,1}, which is not true.

Is there a way to fix it?