I know that the title of this post is wrong, but I got stuck on an example. Consider the graph below, which I obtained from here.

To the best of my knowledge, the tree search version of $A^*$ fails to provide the optimal path, even though the heuristic $h$ seems to be admissible. My search tree would look something like this:
The reason I stop after having found $G$ is because this is how I've seen tree-search algorithms being implemented or described. For example, here and here
which is taken from the book Artificial Intelligence - A Modern Approach. In pseudocode, we see that we return a solution as soon as we've found the goal state, which leads to the same issue seen here. What seems to fix this is that we don't return the moment we find a goal, but wait until we go through the whole queue. Do I have the right idea? Is the pseudo-code laid in the book, and the one from the stackoverflow site, inaccurate because of this?

