Releases: jackielii/structpages
v0.1.8
v0.1.7
Features
Page() Fallback for Static IDs
Added automatic Page() fallback when using static HTML IDs with hx-target that don't match any component method. This simplifies pages that only need Props and Page methods.
Example:
<div hx-target="comments-list" hx-get={urlfor(ListCommentsPartial{})}>type ListCommentsPartial struct{}
func (ListCommentsPartial) Page() component {
return CommentsListView()
}
func (p ListCommentsPartial) Props(r *http.Request) error {
// Just load data, don't need to handle targets
return nil
}Now works without explicit target handling! The framework automatically falls back to Page() for static IDs like:
"body""comments-list""#main-content"- Any custom static ID
How It Works
- Fallback only triggers when
funcValueis not set (Props didn't match the ID to a function) - Works for pages with any number of component methods
- If target matches a component method, that method is called (existing behavior)
- If no match and Page() exists, renders Page() with Props return values
Improvements
- Comprehensive test coverage for edge cases
- Better comments explaining the fallback logic
- Test coverage: 97.8% overall, 93.2% on buildHandler
Breaking Changes
None - this is a new feature that doesn't affect existing code.
v0.1.6
Changes
Bug Fixes
- ID/IDTarget functions now support plain strings: Plain strings passed to
ID()andIDTarget()are returned as-is, giving users full control over the returned valueID(ctx, "body")→"body"IDTarget(ctx, "#my-id")→"#my-id"- Fixes panics when passing string variables to these functions
Improvements
- Added comprehensive test coverage for string handling (98% overall coverage)
- Updated documentation with clearer parameter descriptions
- Better error messages for unsupported types
Breaking Changes
None - this is a bug fix that maintains backward compatibility with existing code.
v0.1.5 - Performance Optimizations
🚀 Performance Optimizations
This release brings significant performance improvements across all hot paths through strategic caching and pre-parsing optimizations.
Key Improvements
1. Cache extractMethodInfo Results ⚡️ 89% Faster
- Global
sync.Mapcache eliminates repeatedruntime.FuncForPCcalls - Zero allocations for unbound method lookups
- Benefits: IDFor 32% faster, extractMethodInfo 80-89% faster
2. Cache parseSegments Results ⚡️ 17% Faster
- Per-context cache with RWMutex for concurrent safety
- Eliminates redundant pattern parsing on every URLFor call
- Benefits: URLFor 10-17% faster, fewer allocations
3. Pre-parse Route Segments ⚡️ Cleaner Hot Path
- Store parsed segments in PageNode during route registration
- extractURLParams middleware uses pre-parsed segments
- Benefits: 3% faster request handling, zero parsing overhead
Performance Gains
| Operation | Before | After | Improvement |
|---|---|---|---|
| extractMethodInfo (unbound) | 75.64ns | 8.459ns | -89% |
| extractMethodInfo (bound) | 87.47ns | 17.83ns | -80% |
| IDFor (unbound method) | 244.0ns | 166.8ns | -32% |
| IDFor (bound method) | 408.2ns | 324.4ns | -21% |
| URLFor (1 param) | 251.5ns | 226.2ns | -10% |
| URLFor (multiple params) | 460.8ns | 384.0ns | -17% |
| URLFor (10x calls) | 2533ns | 2249ns | -11% |
| ServeHTTP with params | 1088ns | 1050ns | -3% |
Memory Improvements
- extractMethodInfo_Unbound: 64B → 0B = zero allocations! ✨
- extractMethodInfo_Bound: 80B → 16B = -80% memory
- URLFor_OneParam: 224B → 176B, -1 alloc
- URLFor_MultipleParams: 539B → 395B, -2 allocs
- URLFor_Repeated_10Times: 2244B → 1763B, -10 allocs
New Features
- Comprehensive Benchmark Suite: 40+ benchmarks covering parsing, routing, URL generation, ID generation, reflection, and end-to-end scenarios
- Performance Documentation: See
PERFORMANCE.mdfor optimization details and future improvement opportunities
Running Benchmarks
# Full benchmark suite
go test -bench=. -benchmem
# Specific categories
go test -bench=BenchmarkRequestHandling -benchmem
go test -bench=BenchmarkURLGeneration -benchmem
go test -bench=BenchmarkIDGeneration -benchmem
go test -bench=BenchmarkReflection -benchmemWho Benefits Most
- 🎯 HTMX Applications: 32% faster ID generation for hx-target attributes
- 🔗 Link-Heavy Pages: 10-17% faster URL generation
- ⚡️ High-Traffic Applications: Reduced GC pressure with fewer allocations
- 📊 All Applications: 80-89% faster reflection operations
Upgrade
go get -u github.com/jackielii/structpages@v0.1.5All optimizations are backward compatible with no API changes required.
Full Changelog: v0.1.4...v0.1.5
v0.1.4: Fix type validation and improve error messages
What's Changed
Bug Fixes
- Prevent panics from
reflect.Call: Added comprehensive type validation to check both argument count and type compatibility before calling functions via reflection - Improved error messages: Error messages now include full context with page names, function paths, and specific type mismatch details
Error Message Improvements
Before:
error executing render operation: argument 1: type string not assignable to parameter type int
After:
error rendering component on page argsComponentTestPage: function github.com/jackielii/structpages.standaloneComponentFunc: argument 1 has type string, expected int
Technical Details
- Added
formatCallable()helper function to extract human-readable function names usingruntime.FuncForPC - Type validation now checks
IsValid()andAssignableTo()for all arguments before calling - Enhanced error context to include page name when available
- Added
TestRenderComponent_TypeMismatchtest to verify type validation
Files Changed
reflect.go: AddedformatCallable()helperstruct_pages_render_component.go: Enhanced validation and error messages inexecuteRenderOpandhandleRenderComponentErrorstruct_pages_test.go: Added type mismatch test and updated existing testsrender_page_component_test.go: Updated test assertions for new error messages
Full Changelog: v0.1.3...v0.1.4
v0.1.3 - Improved Error Messages
Structpages v0.1.3
This release improves error messages to provide better developer experience when working with standalone function components.
Improvements
- Better error messages for unhandled standalone function targets: When an HTMX request targets a standalone function component but the Props method doesn't handle it properly, the error message now provides clear, actionable guidance.
Changes
- Converts kebab-case HX-Target IDs to PascalCase function names in error messages
- Provides exact code examples in error messages showing what to check
- Added comprehensive test demonstrating the error scenario
Error Message Improvements
Before:
page X: target is not a method and Props did not use RenderComponent
After:
page X: Component function 'StandaloneWidgetFunc' is targeted but not handled.
check target.Is(StandaloneWidgetFunc) and call RenderComponent(target, args...).
Or build the component directly and call RenderComponent(component)
Example
If you have a standalone function component like:
func StandaloneWidgetFunc(title string, count int) component { ... }And your HTMX targets it with hx-target="#standalone-widget-func", but your Props method doesn't handle it:
func (p MyPage) Props(r *http.Request, target RenderTarget) (MyProps, error) {
// Missing target.Is(StandaloneWidgetFunc) check!
return MyProps{}, nil
}You'll now get a clear error telling you exactly what to add.
Installation
go get github.com/jackielii/structpages@v0.1.3Full Changelog
Full Changelog: v0.1.2...v0.1.3
v0.1.2 - Argument Validation Fix
Structpages v0.1.2
This release adds additional validation to prevent panics when using RenderComponent with standalone functions.
Bug Fixes
- Fixed panic with standalone functions and incorrect argument counts: Added validation to prevent panic when standalone functions are called with the wrong number of arguments in
RenderComponent(). Previously, only method calls benefited from the DI system's argument validation; standalone functions would panic withreflect: Call with too few/many input arguments.
Changes
- Added argument count validation in
executeRenderOpstruct_pages_render_component.go:172-174 before calling standalone functions - Added comprehensive tests for argument mismatch scenarios:
TestRenderComponent_InsufficientArgs- Tests methods (handled by DI)TestRenderComponent_StandaloneFunctionInsufficientArgs- Tests standalone functions
- Improved error messages to clearly indicate when argument counts don't match
Affected Usage Pattern
This bug affected code like:
func MyStandaloneComponent(arg1 string, arg2 int) component { ... }
// This would panic in v0.1.0 and v0.1.1:
return RenderComponent(MyStandaloneComponent, "only-one-arg")
// Now returns a clear error: "callable expects 2 arguments but got 1"Summary of v0.1.x Fixes
- v0.1.1: Fixed panic with bound methods with arguments
- v0.1.2: Fixed panic with standalone functions with wrong arg count
Installation
go get github.com/jackielii/structpages@v0.1.2Full Changelog
Full Changelog: v0.1.1...v0.1.2
v0.1.1 - Bug Fix Release
Structpages v0.1.1
This is a bug fix release addressing a critical panic in v0.1.0.
Bug Fixes
- Fixed panic with bound methods in RenderComponent: Resolved a critical bug where using bound methods (instance.Method) with arguments in
RenderComponent()would cause a panic with the errorreflect: Call with too few input arguments. The issue was in the bound method detection logic which only recognized methods with zero arguments.
Changes
- Fixed
extractMethodInfo()to properly detect bound methods regardless of argument count - Added better error handling for callable argument mismatches
- Added regression test
TestHandleRenderComponentError_BoundMethodWithArgs - Improved test coverage to 98.6%
Affected Usage Pattern
This bug affected code like:
instance := MyPage{}
boundMethod := instance.ComponentWithArgs
return RenderComponent(boundMethod, "arg1", 42) // Would panic in v0.1.0Installation
go get github.com/jackielii/structpages@v0.1.1Full Changelog
Full Changelog: v0.1.0...v0.1.1
v0.1.0 - First Minor Release
Structpages v0.1.0
This is the first minor release of Structpages, marking a significant milestone in the project's development.
Highlights
- Achieved 100% test coverage for core components
- Improved overall test coverage to 98.1%
- Refactored and unified RenderComponent with renderOp pattern
- Stable API for struct-based routing with Go's standard http.ServeMux
- Full HTMX support with partial rendering
- Type-safe URL generation with UrlFor
- Built-in support for Templ templating engine
Status
This project is in Alpha stage. While the API is stabilizing, breaking changes may still occur in future releases.
Installation
go get github.com/jackielii/structpages@v0.1.0Documentation
See the README and examples in the repository for usage details.
v0.0.20
- Add WithArgs to mount
- Add Option type
- Require Mount to use Option type
Full Changelog: v0.0.19...v0.0.20