How can $build['#attached']['drupalSettings'] change from hook_node_view to javascript? I'm afraid the title isn't clear: I am passing a value from hook_node_view to my javascript in $build['#attached']['drupalSettings'][]. But the value that is set there is not the value that the js is using. I've checked in several places to make sure that this value is indeed the one set in the variable; nevertheless, the js script is getting a different value. I'm sure I'm missing something easy, at least something I should be aware of. The stack trace in the js debugger isn't helpful, so it seems there is some processing happening after the hook is called and the js getting the value in drupal settings.
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.