Repository navigation
Highlights
An audit of v0.9.0 (issues #55–#98) found that the README quick start did not run, route middleware never executed, and state was lost in many ordinary setups. This release fixes 46 issues, makes actions work without an explicit session_start(), adds useFormAction, and runs usephp.js in a real browser on CI.
⚠️ Upgrade notes
- Run
./vendor/bin/usephp publishafter updating. The server andusephp.jschanged together, for example the new form markup,_usephp_snapshots[]and the restore signature. - Forms rendered before the deploy get a
400. Action signatures now cover the page path. Cached snapshot restores made by older pages also get a400, andusephp.jsdiscards that saved snapshot.
⚠️ Breaking changes
- Action forms are bound to their page (#56 → #107). A form can only be posted to the path it was rendered for. Hand-written forms use
signAction($instanceId, $json, $pagePath). HTML rendered on one route and inserted into another page gets a400; use a defer for that. Forms inside a defer are bound to the defer name and accepted on any page, where that page's guard still runs. - Route middleware now runs (#56 → #101). A guard that used to be ignored now applies to GET and to action POSTs. Defer endpoints are not covered, so a protected defer has to check permissions itself.
- Unresolvable components throw (#74, #111). An unregistered class as a route handler, or an unknown name given to
createElement()/render(), throwsLogicExceptioninstead of returning an empty result. A defer whose target is unregistered answers500instead of an empty200. Names that arrive from a request keep their400/404. - Event props (#75).
onFocus,onBlur,onLoadandonErrorthrow. Supported events areonClick,onChange,onInputandonSubmit. - Hook values (#93). Values carried by actions and snapshots must be null, scalars or arrays. Anything else throws when it is rendered.
- Component keys (#71). A fixed key combined with a props key becomes
row/k1, so those components no longer see their earlier state. - Nested defers (#59). An inner defer needs a registered endpoint.
srcdoc(#58). A non-empty value throws.- Generated markup (#77). Action buttons are
<button form="…">with a separate hidden form. CSS or scripts that relied on the old wrapping form need updating. style/scriptchildren are raw (#85). Do not put user input in them. A closing tag in the content throws.- PSX (#84). Built-in tags compile to
createElement(), so attribute order follows the source. Cached output is recompiled once.
Security fixes
- Route guards were never run (#56 → #101, #107). Includes the bypass of posting a guarded page's signed form to an unguarded URL, and of using
restoreto get a form signed for another page. - Session data in shared caches (#59 → #100, #109 → #114). Nested defers were inlined under the parent's public
Cache-Control. A public defer could also sendSet-Cookie, a CSRF token or a session-bound signature. Those responses are nowprivate, no-storewith a logged warning. javascript:block bypass (#57 → #99). Tabs and newlines inside a URL are removed before the check. Attribute and scheme checks ignore case.srcdocscripts ran (#58 → #99).- Malformed snapshots caused a 500 (#86 → #101).
?_snapshot[]=1hit every route. Invalid input is now a verification failure, and a bad POST is a400.
Added
useFormAction(['field' => $setter])(#76 → #105). Copies submitted fields intouseState. Which field goes to which hook is signed. The values are not signed, so treat them as untrusted input.- Element events (#75 → #105).
onClickon any element, plusonChange,onInput(300 ms debounce) andonSubmit. Without JavaScript, onlyonClickon buttons and submit or image inputs andonSubmitwork. - Arbitrary attributes on every
H::*tag (#94 → #105).H::div(title: 'x', role: 'alert'),H::button(...['aria-label' => 'x']). - Route middleware API (#56 → #101). Takes
(array $params, RequestContext $request). Returnnullortrueto continue,falsefor a 403, or a string orElementto answer with it.runRouteMiddleware()is available for custom front controllers.
Fixes
- Actions and partial updates (#104). No
session_start()needed (#55).fc()with Session or Memory updates in place (#78, #96). Class components keep Snapshot state on Session and Persistent routes (#63). Redirects keep the query string (#64).useRouter()['params']survives a partial update (#65). - Snapshots (#106). Session and Shared store one snapshot per instance, up to 64 (#67). A parent update keeps its children's state (#68). Isolated routes without JavaScript answer the POST directly, so state is kept (#69).
- Client (#103, #105, #106). Partial updates morph the DOM, so input, focus and selection survive (#79). A double click sends one POST (part of #80). Parent and child components update in turn, and fixed-value clicks made meanwhile are dropped.
- Hooks (#100, #116).
useEffectcleanup no longer crashes the session (#60, #61).setState(null)keeps null (#66). A parent's hooks stay with the parent after a child renders orrender()is nested (#70, #73, #112). Int keys work (#72). - Rendering (#99, #105). Nested children are flattened (#62). Invalid UTF-8 no longer empties text (#88).
aria-hidden={false}and similar attributes are kept (#95). A button inside an app's form no longer nests forms (#77). - Router (#101). Literal route text is escaped (#89). HEAD falls back to GET (#90). Parameters are decoded (#91).
- PSX (#102).
{/* comment */},{$x && <b/>},<style>and<script>compile correctly, and invalid output is a compile error (#81, #82). Entities are decoded (#83).{0}andwidth="100"work understrict_types(#84).usephp compileexits 1 on a missing path (#97).
Docs
- The README quick start now runs, and CI executes the README code (#98 → #108).
->name(),generate(),navigateandisActivewere removed from the docs because they never existed. - State sharing across route parameters is documented, with how to set keys (#92).
Tests
- 464 → 1211 PHPUnit tests, 6220 assertions. PHPStan and php-cs-fixer clean.
- New 79 Playwright tests for
usephp.jsrun on CI (#110 → #117).
Known limitations
- #80: with several tabs, the last write wins, and there is no
fn($prev)update. - #87: HTML size grows with the square of the row count when one state holds a whole list. Reported to exceed
memory_limit=128Mat 1000 rows.
Full Changelog: v0.9.0...v0.10.0