Preheat the oven to 400°F (200°C). Fit your pie crust into a 9-inch pie pan and shape or crimp the edges as desired. Carefully line the crust with parchment paper and fill with pie weights or dried beans to prevent puffing. Blind-bake for 20 minutes, then remove the weights and parchment. Continue baking for an additional 10 to 15 minutes, or until the crust is dry, crisp, and golden. Set aside to cool completely before filling.
In a medium saucepan, whisk together the sugar and cocoa powder until fully combined. Gradually whisk in 1½ cups of the milk, ensuring no dry lumps remain. Place the saucepan over medium-high heat and bring the mixture to a gentle simmer, stirring regularly to avoid scorching.
While the cocoa mixture heats, prepare the egg base in a separate heatproof mixing bowl. Whisk together the remaining ½ cup of milk, egg yolks, flour, and salt until smooth and well combined.
Once the chocolate milk mixture begins to simmer, slowly pour it into the egg mixture, whisking constantly to temper the yolks without scrambling them. Once fully incorporated, return the combined mixture to the saucepan.
Cook over medium-low heat, stirring continuously with a spatula or wooden spoon, until the mixture thickens and starts to bubble—this should take about 5 minutes. Remove the pan from the heat and immediately stir in the cubed butter and vanilla extract. Mix until the butter is fully melted and the filling is glossy and smooth.
For an ultra-smooth finish, strain the filling through a fine mesh sieve directly into the cooled pie shell. Spread evenly and smooth the surface with a spatula.
Refrigerate the pie uncovered for at least 4 hours, or preferably overnight, to allow the filling to fully set. Before serving, top each slice with a generous spoonful of whipped cream if desired. Store any leftovers covered in the refrigerator for up to one week.