Melt the butter in a large pot over a medium heat, then add the onions, garlic, thyme sprigs and brown sugar, if using. Cook, stirring once or twice, for about 10 to 15 minutes, until all the onions are caramelised.
Add the flour and cook for a further 2 minutes to dry up the liquid and coat the onions. Pour in the wine, which will immediately begin to thicken as it reacts with the flour.
Gradually add the beef stock and stir slowly, then simmer for about 45 minutes, until the onions are soft and the soup is highly flavoured.
Meanwhile, cut the bread into slices about 1.25cm thick and sprinkle with the grated cheese. Grill or bake in the oven at 180°C/ gas mark 4 until the cheese is melted and the bread is crispy. Serve on top of the fragrant soup.