Lightly spray an 8x8-inch baking pan with cooking spray.
In a large saucepan, bring coconut milk to a gentle boil.
In a small mixing bowl, whisk sugar, cornstarch, water, and vanilla until smooth and lump free.
Whisk cornstarch mixture into hot coconut milk. Cook pudding pver medium heat, stirring very frequently with a silicone spatular or a wooden spoon for about 20 min, until pudding has thickened enough to pull away from sides of pan when it's being stirred. Remove pan from heat and scrape pudding into prepared baking pan. Let cool at room temperature for 10-15 min, then refrigerate until thoroughly chilled, at least 2 hours.
If desired, toast sweetened flaked coconut in a small skillet set over med-high heat. Stir frequently and remove from heat when golden brown and fragrant, 2-5 minutes. Set aside until ready to serve dessert.
To serve, cut chilled haupia into 12 squares using a sharp knife. Lift individual squares onto dessert plates. If desired, top each square with diced pineaple and toasted coconut.