Live data from Hacker News

Show HN: Use Go's HTML/template to write React-like code

news.ycombinator.com

81–90 of 96 posts

Re: Show HN: Use Go's HTML/template to write React-like code

#81
post #33
post #27

A bit off-topic, and maybe it was just an example made without too much thought put into it, but I've noticed there seems to be a lot of people now who write button/links like this: My Button As far as I know that's technically invalid HTML. You can't have an as a child of a (or even the other way around.) I'm also ignoring the invalid type="submit" against the tag in the example button component in the post. I think…

> As far as I know that's technically invalid HTML. You can't have an as a child of a (or even the other way around.) I'm also ignoring the invalid type="submit" against the tag in the example button component in the post. It definitely feels weird to have anything other than text nodes inside , didn't realize it's actually invalid HTML. I used this approach mainly to have the button component behave as a link button…

A button with type "submit" will happily submit the form when you click on it. If you want it to look like a link, use CSS. Putting the submit on the anchor tag is pointless- the lack of a type on the button itself means the browser is inferring the intended behavior and defaulting to type "submit" rather than type "button".

As others have mentioned, the main downside is likely accessibility.

Re: Show HN: Use Go's HTML/template to write React-like code

#82
You can use go’s builtin build features and embed the results into a http.FS.

  go generate npm build
  go build
And declaring the resulting frontend build as an embed.FS using

  //go:embed dist/
  var frontend *embed.FS
And use that in a http.FS

https://blog.logrocket.com/using-go-generate-reduce-boilerpl...

Re: Show HN: Use Go's HTML/template to write React-like code

#83

I've been doing something very similar in Rust recently using Askama or Maud for templates (components), optionally with Axum to include a server in the binary. The author mentions wanting to colocate templates with logic, Maud allows much tighter/automatic integration in this regard. This approach also synergizes almost perfectly with HTMX.

Recently rediscovered htmx and applied it to a Django project. It really does give that SPA feeling without much of a hassle, and it's also easier in a team setting where there's less stepping on other people's toes, which is often the case with a full blown Vue or React app.

Re: Show HN: Use Go's HTML/template to write React-like code

#84
post #17

Earlier quoted context omitted.

There eventually has to be JavaScript somewhere, and once you have to use that for any dynamic frontend, might as well use a proper JS/TS framework. Not being a frontend person first, I have learned to choose whatever they are using these days. It will be hard to hire, onboard, and maintain anything that strays too far for the normal patterns they use. Next has skyrocketed in popularity for a reason. It makes the Rea…

> There eventually has to be JavaScript somewhere, and once you have to use that for any dynamic frontend, might as well use a proper JS/TS framework. Yes, totally understand it's hard to escape JS in Web frontend. Even writing a simple dropdown requires a little bit of JS. > Not being a frontend person first, I have learned to choose whatever they are using these days. It will be hard to hire, onboard, and maintain…

If you really want, you can avoid JS for drop down menus too. I've seen the CSS hover [1] and the summary/details [2] approach before. My recent sites use Bulma for all the styling, so the only JavaScript I'm using is the toggle for the navbar burger icon on small screens [3].

[1] https://www.w3schools.com/Css/css_dropdowns.asp

[2] https://codepen.io/Ajay-Anand/pen/OJoZjPd

[3] https://bulma.io/documentation/components/navbar/

Re: Show HN: Use Go's HTML/template to write React-like code

#85
post #80
post #36

Earlier quoted context omitted.

Once the major browser engines support it, it's de-facto legal. This also explains why there are so few alternative browsers. Writing a new browser that supports everything that happens to work in the major browsers is ridiculously hard.

> Once the major browser engines support it, it's de-facto legal. thats madness. just because the browser allows it, doesn't mean you should do it.

"Legal" is not the same as "recommended".

Re: Show HN: Use Go's HTML/template to write React-like code

#87

You can use go’s builtin build features and embed the results into a http.FS. go generate npm build go build And declaring the resulting frontend build as an embed.FS using //go:embed dist/ var frontend *embed.FS And use that in a http.FS https://blog.logrocket.com/using-go-generate-reduce-boilerpl...

Yeah this is what I do to. The OP's approach is interesting but I think that using typescript/javascript/whatever to build your app, then "render" using a build step (like `vite build` or whatever) and embedding the resulting static bundles is the best of both worlds.

That said, the JS ecosystem is so weird that I totally understand the urge to bail entirely and do things in Go. But JS/TS and all the related frameworks really are decent if you pick a reasonable subset of them.

Re: Show HN: Use Go's HTML/template to write React-like code

#88
post #38

Earlier quoted context omitted.

The big innovation of the html5 spec was to specify how to handle all the “invalid” html states; recovery from user error is now part of the spec instead of wholly implementation specific.

HTML 5's error recovery pseudocode replaced the formal grammar that HTML 4 had, and in authoring I find it harder to take guidance from.

Well, what's the point of having a formal grammar if nobody follows it and things outside the grammar have defined behavior?

Re: Show HN: Use Go's HTML/template to write React-like code

#89
post #24

My style for building web app. I was never convinced that doing everything on JS layer is a good thing (regardless the backend language). But you need to show more interactivity to convince the JS people. I personally like this style and add HTMX for partial updates.

It depends strongly on what you’re building. Interactivity is a property of the app and different types of apps have different interactivity requirements. For example a page that is more or less a UI proxy for CRUD operations typically does not require too much client side state. On the otherhand, a flow chart editor (any document editor really) needs to function largely without round trips to the server. If the web…

Good perspective, thanks, this is the kind of information that is often hard to find: deciding on a tech stack is nuanced, is more than preferences. I am looking for a good source of information about approaches to application architectures that is relevant to modern times.

Re: Show HN: Use Go's HTML/template to write React-like code

#90
I have something kind of similar written in Common Lisp, however it uses stock HTML and then lisp. A template is a literal HTML template element, and it's referenced with custom elements. So `` is in the file that will be compiled, say indet.html, and then there is a my-el.html file which is the reference that is inserted into the `` as a child. This file is just stock HTML with a `` as the root element and then whatever in that. This is all rendered properly by the browser because it is just standard HTML. The slot element can be used to inject into these template els. All the lisp does really is recursively compile the HTML and then manage any logic writtel inside of `` tags

It actually supports any language, long as you define the lang= name in a config file to tell the compiler how to process it. Ie for python `python="python -m '$'"` would then let the cl compiler know how to handle ``.

Post reply on HN