In a large skillet over medium heat, add olive oil and sliced onions. Cook for about 15-20 minutes, stirring frequently until the onions are soft and caramelized.
Add the balsamic vinegar, sugar, thyme, salt, and pepper. Stir well and cook for another 5 minutes, allowing the flavors to meld. Remove from heat and let cool slightly.
Roll out the puff pastry on a lightly floured surface and cut into squares or rounds to fit your tart pans or a baking sheet.
Place the pastry pieces onto your prepared baking sheet or in individual tart pans. Pre-bake the pastry for 10 minutes until slightly puffed.
In a mixing bowl, combine the ricotta cheese, half of the Gruyère cheese, and season with salt and pepper. Spread this mixture evenly over the pre-baked pastry.
Top the cheese mixture with the caramelized onions, distributing evenly. Sprinkle the remaining Gruyère cheese on top.
Beat the egg in a small bowl and brush the edges of the pastry with the egg wash for a golden finish.
Bake the tarts in the preheated oven for 15-20 minutes until the cheese is bubbly and the pastry is golden brown.
Remove from the oven and let cool for a few minutes before serving.
Notes
Serve the tarts warm, garnished with fresh thyme or arugula for a pop of color, and a drizzle of balsamic glaze for added flavor.