For users that create visualisations via the Kibana UI using the "clicky" option, how could this check be included to make sure all visualisation scripts include it?
for the "clicky"-users nothing really changes in how they should use the UX.
It does mean that for users who have existing scripted fields in an index pattern (https://www.elastic.co/guide/en/kibana/current/scripted-fields.html), you might have to add that if-check.
Also, would you suggest we upgrade Kibana to the latest version? Would that fix this issue?
It's more of the other way around. If you upgrade (e.g from 6.x to 7.x), you would need to inspect your existing scripted-fields and see if they need that additional check. So upgrading will require you to add that
.size() condition if you're reading out values from a document.