Skip to content

Add "Static" func#325

Open
guillemus wants to merge 2 commits into
maragudk:mainfrom
guillemus:main
Open

Add "Static" func#325
guillemus wants to merge 2 commits into
maragudk:mainfrom
guillemus:main

Conversation

@guillemus

@guillemus guillemus commented Jun 5, 2026

Copy link
Copy Markdown

As discussed here #323 , here's the Static implementation.

@markuswustenberg I did add the static func at "gomponents.go". It feels enough of a primitive to be there I think?

@guillemus
guillemus marked this pull request as ready for review June 5, 2026 22:01

@markuswustenberg markuswustenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss the implementation details a bit more, if you're up for it. :-)

If you'd rather not, feel free to let me know, and we can merge and I'll iterate myself.

Comment thread gomponents_test.go
Comment on lines +470 to +473
staticHead := g.Static(h.Head(
h.TitleEl(g.Text("My site")),
h.Link(h.Rel("stylesheet"), h.Href("/app.css")),
))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking a bit about the usage of this. It's a shame you lose the ability to inline the Static component like you usually would with all the other components, and that you have to keep the node variable (staticHead here) somewhere as state between requests.

Would it be nicer to perhaps pass a string pointer or something, that the receiving function renders to if non-empty? And subsequent requests see the non-empty pointer value and just use that.

Comment thread README.md
- `Map` for mapping data to components and `Group` for grouping components,
- and `If`/`Iff` for conditional rendering.
- `If`/`Iff` for conditional rendering,
- and `Static` for caching large static element trees.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely rather want this in the components package, like the other specialized helpers there. I don't see it as a low-level primitive. Could you move it there?

@guillemus

Copy link
Copy Markdown
Author

Hey @markuswustenberg ! there will probably be lots of back and forth, and this pr requires more taste than tedious work really. The code by itself is very small.

Feel free to merge this / close this pr and implement it the way you want it. I thought more about the global key val cache that you proposed, could be another interesting approach, I might have overrated the complexity.

@markuswustenberg

Copy link
Copy Markdown
Member

Okay, thank you for the reply and your work so far. I'll try some stuff out when I have some spare time. :-)

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3d2c3fb) to head (51974de).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #325   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          633       647   +14     
=========================================
+ Hits           633       647   +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants