Invalid HTML templates should fail to compile #13158

Open
opened 2025-11-02 10:33:07 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @jtran on GitHub (Jun 14, 2024).

Feature Description

For a long time, I've wished that HTML templates would fail to compile when referencing a variable that doesn't exist or in other obviously wrong scenarios. Because of the way Gitea uses maps and template helpers now, this is currently not the case.

Could we switch to Templ? https://github.com/a-h/templ

I floated the idea in Gitea's Discord, and some people seemed interested.

I heard that maintainer sentiment is generally positive, but that was in 2023 and there were a few concerns:

  • What are all the differences? We'd like to know so that we can understand the amount of effort in migrating. Perhaps a migration guide could be helpful.
  • Difficulty of making the change while other frontend changes are being made. Perhaps it means coordination with other initiatives.
  • Security of the library, contrasted with the current more battle-tested one. templ has a security guide section. Perhaps an audit of the source needs to be done.
  • How would this work with template customization [link]? Would customization still work? Would users need to recompile when they change their custom templates? Gitea routinely makes breaking changes to custom templates; would this improve that situation?

I understand that this is a big undertaking. I'm opening the issue to have a place to put the conversation for anyone else thinking about a similar thing.

I apologize in advance if there's already another plan in place that I don't know about.

Screenshots

No response

Originally created by @jtran on GitHub (Jun 14, 2024). ### Feature Description For a long time, I've wished that HTML templates would fail to compile when referencing a variable that doesn't exist or in other obviously wrong scenarios. Because of the way Gitea uses maps and template helpers now, this is currently not the case. Could we switch to Templ? https://github.com/a-h/templ I floated the idea in [Gitea's Discord](https://discord.com/channels/322538954119184384/322910365237248000/1183782454415339631), and some people seemed interested. I heard that maintainer sentiment is generally positive, but that was in 2023 and there were a few concerns: - What are all the differences? We'd like to know so that we can understand the amount of effort in migrating. Perhaps a migration guide could be helpful. - Difficulty of making the change while other frontend changes are being made. Perhaps it means coordination with other initiatives. - Security of the library, contrasted with the current more battle-tested one. templ has a [security guide section](https://templ.guide/security/injection-attacks). Perhaps an audit of the source needs to be done. - How would this work with template customization [[link]](https://discord.com/channels/322538954119184384/322910365237248000/1184149256672649286)? Would customization still work? Would users need to recompile when they change their custom templates? Gitea routinely makes breaking changes to custom templates; would this improve that situation? I understand that this is a big undertaking. I'm opening the issue to have a place to put the conversation for anyone else thinking about a similar thing. I apologize in advance if there's already another plan in place that I don't know about. ### Screenshots _No response_
GiteaMirror added the type/proposal label 2025-11-02 10:33:07 -06:00
Author
Owner

@lunny commented on GitHub (Jun 15, 2024):

Maybe not in compile, we can have a template test tool or sub-command to test whether the template will fail. I think this is an easier way to resolve the current problem. i.e. We can have a ./gitea doctor check-templates to check the templates. And changing the template system could be a long-term plan which can be discussed more.

@lunny commented on GitHub (Jun 15, 2024): Maybe not in compile, we can have a template test tool or sub-command to test whether the template will fail. I think this is an easier way to resolve the current problem. i.e. We can have a `./gitea doctor check-templates` to check the templates. And changing the template system could be a long-term plan which can be discussed more.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#13158