That abrupt shift to familiar and optimistic Star Wars concepts allows the film to end the way it does while not necessarily feeling as dark as it may initially seem.
We watch our heroes die in pretty grisly fashion, but their sacrifices ultimately mean something profound in this universe.
From there, the intense Darth Vader action scene and the real promise of hope for the future by Princess Leia lead us into the credits with the assurance that things will work out in the end.
Although Rogue One: A Star Wars Story technically ends on a somewhat tragic note for our main heroes, John Gilroy seems to think that the final minutes of the movie do quite a bit of work with regards to lightening up the overall tone of the film.