In a large skillet, heat the olive oil over medium heat. Add the sliced onions, stirring occasionally.
Cook the onions for about 15 minutes until they start to soften. Add sugar, balsamic vinegar, thyme, salt, and pepper. Continue to cook for another 20-25 minutes or until the onions are deeply caramelized and golden brown. Stir occasionally to prevent sticking.
Roll out the puff pastry on a lightly floured surface to fit your tart pan. Carefully transfer the pastry to the pan, pressing it into the edges. Prick the bottom with a fork to prevent it from puffing up.
In a bowl, combine the Gruyère and ricotta cheese, mixing well. Spread this cheese mixture evenly over the pastry base.
Once the onions are caramelized, layer them on top of the cheese mixture in the tart.
Brush the edges of the pastry with the beaten egg to achieve a golden crust.
Bake the tart in the preheated oven for 25-30 minutes or until the pastry is golden and puffed.
Remove from the oven and let it cool for a few minutes before slicing and serving.
Notes
Serve warm, garnished with a sprinkle of fresh thyme and a drizzle of balsamic reduction for an elegant touch.