How can $build['#attached']['drupalSettings'] change from hook_node_view to javascript?
I had strongly suspected a caching issue while ignoring something more obvious, that the hook was being called several times and passing the value of the last time it's called to the javascript. Just added a check to make sure it's passing the correct value and it solved the issue.