It does not do that when there’s a heap of caramelized onions on top of the patty. The cheese nestles in quite nicely with the onions and seals them in place, plus the dome of onions increases surface space on top of the patty so a slice of cheese doesn’t melt off the side that much.