-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
templ generate fails on a large file #1049
Comments
Use SVG sprites for easier filtering by running the SVGs through an optimizer to reduce their size. You can then include the sprites using a common component like Icon and specify the ID of the chunk in the sprite. The advantage of this approach is that it doesn't bloat the HTML response, and static resources are processed by the browser as static content, benefiting from features like caching. package static
import "..../components/shared"
type icon struct {
Icon shared.SpritesBase `json:"icon"`
IconClass templ.CSSClasses `json:"icon-class"`
}
type IconOption func(*icon)
templ (i *icon) render() {
<svg class={ i.IconClass }>
<use crossorigin="anonymous" xlink:href={ i.Icon.SpritePath() }></use>
</svg>
}
func WithIconClass(iconClass templ.CSSClasses) IconOption {
return func(i *icon) {
i.IconClass = iconClass
}
}
func NewIcon(iconName shared.SpritesBase, options ...IconOption) templ.Component {
newIcon := &icon{
Icon: iconName,
IconClass: templ.Classes("w-4", "h-4", "flex-shrink-0"),
}
for _, opt := range options {
opt(newIcon)
}
return newIcon.render()
} To preserve types, you can use a pass through the sprite to generate constants. package sprites
type SpriteSprite string
func (sprite SpriteSprite) SpritePath() string {
return "/public/sprite.svg#" + string(sprite)
}
const (
SPRITE_A_ARROW_DOWN SpriteSprite = "a-arrow-down"
SPRITE_A_ARROW_UP SpriteSprite = "a-arrow-up"
SPRITE_A_LARGE_SMALL SpriteSprite = "a-large-small"
SPRITE_ACCESSIBILITY SpriteSprite = "accessibility"
SPRITE_ACTIVITY SpriteSprite = "activity"
SPRITE_AIR_VENT SpriteSprite = "air-vent"
SPRITE_AIRPLAY SpriteSprite = "airplay"
SPRITE_ALARM_CLOCK SpriteSprite = "alarm-clock"
) <td>
<span class="flex gap-2 items-center">
@static.NewIcon(sprites.SPRITE_LANGUAGES, static.WithIconClass(templ.Classes("w-8 h-8")))
<span class="flex flex-col">
<span class="font-bold">{ item.GetKey() }</span>
<span class="text-xs">{ item.GetScope() }</span>
</span>
</span>
</td> |
Thank you for the suggestion! I'll look into that. |
TLDR: It fails on the 101st TestingThis is all testing a single file. templateparser.go log.Print(pi.Peek(1))
log.Print(pi.Peek(2))
log.Print(pi.Peek(3))
if _, ok, err = parse.All(openBraceWithOptionalPadding, parse.StringFrom(parse.Optional(parse.NewLine))).Parse(pi); err != nil || !ok {
err = parse.Error("templ: malformed templ expression, expected `templ functionName() {`", pi.PositionAt(start))
return
} Outputs when running using the provided file.
Despite it being potentially caused by the 101st More Testing on Input DataIf you remove the I did also test if a file with a lot (499) of if/else branches wrapped in templ functionName(props Props) {
} |
The templ parser for some elements has some look ahead limits - ie it will only look for a closing brace that's x characters ahead, it's likely this file is hitting those because of the inclusion of large quantities of data in the file. It could be a case of reviewing those limits, but I haven't had chance to look into this yet. |
Describe the Bug
The
templ generate
command fails to generate.go
code for a large file, citing syntax errors. However, when the file is divided into smaller parts, the generation works without any issues.To Reproduce
Steps to reproduce the behavior:
templ generate
on the following file: Gist LinkExpected Behavior
The
.go
code should be generated successfully without errors, even for large files.Screenshots
Logs
templ info
OutputThe text was updated successfully, but these errors were encountered: