diff --git a/.version b/.version
index 5629baa03..b4cddf5b1 100644
--- a/.version
+++ b/.version
@@ -1 +1 @@
-0.2.700
\ No newline at end of file
+0.2.702
\ No newline at end of file
diff --git a/generator/generator.go b/generator/generator.go
index 0387dee1d..404bdb733 100644
--- a/generator/generator.go
+++ b/generator/generator.go
@@ -893,7 +893,7 @@ func (g *generator) writeElement(indentLevel int, n parser.Element) (err error)
return err
}
//
- if err = g.writeElementScript(indentLevel, n); err != nil {
+ if err = g.writeElementScript(indentLevel, n.Attributes); err != nil {
return err
}
//
+ if err = g.writeElementScript(indentLevel, n.Attributes); err != nil {
+ return err
+ }
//
+
+
diff --git a/generator/test-script-usage/template.templ b/generator/test-script-usage/template.templ
index 9364a7525..e98fc834c 100644
--- a/generator/test-script-usage/template.templ
+++ b/generator/test-script-usage/template.templ
@@ -27,6 +27,7 @@ templ ThreeButtons() {
@Conditional(true)
+ @ScriptOnLoad()
}
script conditionalScript() {
@@ -42,3 +43,11 @@ templ Conditional(show bool) {
}
/>
}
+
+script alertTest() {
+ alert('testing');
+}
+
+templ ScriptOnLoad() {
+
+}
diff --git a/generator/test-script-usage/template_templ.go b/generator/test-script-usage/template_templ.go
index 716f96d20..d7a5512e1 100644
--- a/generator/test-script-usage/template_templ.go
+++ b/generator/test-script-usage/template_templ.go
@@ -154,6 +154,10 @@ func ThreeButtons() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+ templ_7745c5c3_Err = ScriptOnLoad().Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
@@ -217,3 +221,50 @@ func Conditional(show bool) templ.Component {
return templ_7745c5c3_Err
})
}
+
+func alertTest() templ.ComponentScript {
+ return templ.ComponentScript{
+ Name: `__templ_alertTest_eadf`,
+ Function: `function __templ_alertTest_eadf(){alert('testing');
+}`,
+ Call: templ.SafeScript(`__templ_alertTest_eadf`),
+ CallInline: templ.SafeScriptInline(`__templ_alertTest_eadf`),
+ }
+}
+
+func ScriptOnLoad() templ.Component {
+ return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
+ if !templ_7745c5c3_IsBuffer {
+ templ_7745c5c3_Buffer = templ.GetBuffer()
+ defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var9 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var9 == nil {
+ templ_7745c5c3_Var9 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, alertTest())
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if !templ_7745c5c3_IsBuffer {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
+ }
+ return templ_7745c5c3_Err
+ })
+}