-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e95ed17
commit 01e759b
Showing
5 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 2. Adopt Templ for UI components | ||
|
||
Date: 2024-08-02 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
We have used Golang's native HTML templating in all our microfrontends to date, but there are some frustrations. The | ||
Handlebars syntax does allow for some conditional logic and template composition, but it is incomplete. Templates accept | ||
variables but only as an empty interface, so there is no type safety or intellisense, so a simple misspelled variable | ||
will result in runtime errors. They are also hard to test, meaning our Cypress tests have become page-level component | ||
tests, rather than system-level end-to-end tests. | ||
|
||
## Decision | ||
|
||
[Templ](https://templ.guide/) is a widely adopted HTML component generator where components are described as Go functions. | ||
The syntax uses valid HTML, meaning converting our existing designs and templates should be fairly straight-forward, but | ||
allows full use of everything Go has to offer, including typed function parameters. As components are functions, they can | ||
be passed to other components as function parameters. The `.templ` are then transpiled to `.go` files in a compile step, | ||
and then can be imported into other packages. | ||
|
||
This also allows for a better separation of state. Previously, we have run into issues where templates used the same structs | ||
as were used for the API, which coupled the two use cases and made it hard to modify (not to mention being a common cause | ||
of runtime errors). With Templ, we can keep all view state in the `components` package, with the separation enforced by | ||
Go not allowing circular dependencies between packages. | ||
|
||
## Consequences | ||
|
||
Adopting any library outside of the standard library brings risk. However, Templ is very widely adopted, especially when | ||
paired with HTMX, and in active development. It is also another technology to learn, though is arguably easier to understand | ||
in regard to component composition. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
"lib": ["es5", "dom"], | ||
"types": ["cypress", "node"] | ||
}, | ||
"include": ["**/*.ts"] | ||
"include": ["cypress/**/*.ts"] | ||
} |