You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
RenderScriptItems is called everytime even though the ComponentScript is incapsulated in an if condition.
To Reproduce
A small, self-container, complete reproduction, uploaded to a Github repo, containing the minimum amount of files required to reproduce the behaviour, along with a list of commands that need to be run. Keep it simple.
templ info output
Run templ info and include the output.
(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/Users/user/.goenv/versions/1.22.0/bin/go version=go version go1.22.0 darwin/arm64 ]
(✓) gopls [ location=/Users/user/go/1.22.0/bin/gopls version=golang.org/x/tools/gopls v0.16.1 ]
(✓) templ [ location=/Users/user/go/1.22.0/bin/templ version=v0.2.771 ]
Desktop (please complete the following information):
OS: MacOS
templ CLI version (templ version): v0.2.771
Go version (go version): go version go1.22.0 darwin/arm64
gopls version (gopls version): golang.org/x/tools/gopls v0.16.1
Additional context
I suppose ComponentScript needs to be rendered before its used, however it does not accept nil values.
I imagine the solution would be to accept nil ComponentScript but ignore them.
The text was updated successfully, but these errors were encountered:
luxxxoor
changed the title
ComponentScript rendered even when 'if condition' fails
bug: ComponentScript rendered even when 'if condition' fails
Aug 27, 2024
Thanks for raising! I agree that this is unexpected behaviour. And the reasoning is because the order of operations is:
Render all scripts referenced by the elements attributes (if not already rendered)
Render <div open tag
Render attributes coditionally
So I think the solution needs to be that we modify the generated code so that the conditional is evaluated earlier and used to inform both the rendering of scripts and the rendering of attributes.
Describe the bug
RenderScriptItems is called everytime even though the ComponentScript is incapsulated in an if condition.
To Reproduce
A small, self-container, complete reproduction, uploaded to a Github repo, containing the minimum amount of files required to reproduce the behaviour, along with a list of commands that need to be run. Keep it simple.
Expected behaviour
I expect passing a nil action to not break rendering of the button.
Screenshots
N/A
Logs
templ info
outputRun
templ info
and include the output.Desktop (please complete the following information):
templ version
): v0.2.771go version
): go version go1.22.0 darwin/arm64gopls
version (gopls version
): golang.org/x/tools/gopls v0.16.1Additional context
I suppose ComponentScript needs to be rendered before its used, however it does not accept nil values.
I imagine the solution would be to accept nil ComponentScript but ignore them.
The text was updated successfully, but these errors were encountered: