How to update node location so that it works with view_selected()

Hello, I am trying to create a new node in the Shader Editor, change its location and make the view align to it.
But after I change the node’s location via node.location = x,y and try to perform node.view_selected(), it aligns the view to the original node location (which is 0,0; origin) instead of the new changed location. I tried using node.update() but that doesn’t seem to be working. How can I make it work?

        node = tree.nodes.new("NodeReroute")
        node.location = Xmin, Ymin
        #node.update()
        
        for node in tree.nodes:
            node.select = False

        tree.nodes[-1].select = True
        
        bpy.ops.node.view_selected()

Otherwise, is there any other way to align view2d to given co-ords? I can’t seem to find anything in the docs.
Thanks