Description
In the current implementation, there is an assumption that all the parts are rendered in a single thread. Context value for children is modified for the whole context. If snippets need to be rendered in goroutines, it creates a race condition where children go missing or sporadically added
To Reproduce
https://github.com/kanstantsin-chernik/templ/blob/suspense-async-rendered/examples/suspense-async-rendered/main.templ
I also added comments to the generated code
Expected behavior
Each templ component is independent and can be rendered in a goroutine
Logs
WARNING: DATA RACE
Read at 0x00c01e4a13f0 by goroutine 1053:
github.com/a-h/templ.GetChildren()
external/com_github_a_h_templ/runtime.go:78 +0x186
Previous write at 0x00c01e4a13f0 by goroutine 1054:
github.com/a-h/templ.ClearChildren()
external/com_github_a_h_templ/runtime.go:68 +0x44
templ info
output
% templ info
(✓) os [ goos=linux goarch=amd64 ]
(✓) go [ location=/home/user/go-code/bin/go version=go version go1.23.2 X:nocoverageredesign linux/amd64 ]
(✓) gopls [ location=/opt/go/path/bin/gopls version=golang.org/x/tools/gopls v0.14.2
golang.org/x/tools/[email protected] h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc= ]
(✓) templ [ location=/home/user/go-code/bin/templ version=v0.2.778 ]
Desktop (please complete the following information):
- OS: all
- templ CLI version (
templ version
): v0.2.778 - Go version (
go version
): go version go1.23.2 X:nocoverageredesign linux/amd64 gopls
version (gopls version
):golang.org/x/tools/gopls v0.14.2
Additional context