How can I prevent texture stretching while scaling a mesh?

Since for some reason I’m not able to edit my message:
I tried the technique in the video @anonymous_user_dcd9d04a posted, and now texture tiling is working perfectly!

Pay attention to transform node, it should convert world to local space.

Any ideas on doing this for UI? When i try this it just crashes when the material is set to UI.