Reference › Project
clarusjs 0.11.0
All releases · [email protected] on npm
Minor Changes
- Component loaders: a
.load.tsnext to a component (outsidesrc/pages) loads that component's data. Before a page renders, every component loader it uses (however deeply nested) runs in parallel with the route's context (params,request,cookies,locals), then the page renders synchronously with the results, which fill each component's inputs (props from the parent win). Static pages run them at build, server routes per request; client routes don't support them yet (an error). #334 clarusjs({ compress: true }):vite buildwrites.brand.gznext to each HTML, JS, CSS, SVG, JSON and XML file indist/client(Node'szlib, no dependency), each kept only when smaller, for servers that serve precompressed files directly (nginxgzip_static/brotli_static, Caddyprecompressed). #313- Cookies and locals in loaders, with a request hook: every
load()getscookies(get,getAll,set,delete; what's set goes on the answer asSet-Cookie, with secure defaults:path: '/',httpOnly,sameSite: 'lax', andsecureeverywhere but the Vite dev server) andlocals. An optionalsrc/server.tsexportshandle({ request, cookies, locals }), run once per request before any page loads; returning a Response (such asredirect('/login')) answers instead.Localsis declared once with module augmentation and checked in every loader. New types:LoadContext,Cookies,CookieOptions,Locals,Handle. #327 - Endpoints: a
.tsfile undersrc/pages(not.load.ts) exportingGET,POST,PUT,PATCH,DELETEorOPTIONShandlers answers at its route, with the same context asload()(request, params, cookies, locals), served by the same handler in dev, preview and production (and the Netlify adapter). Cross-site writes are refused (403) by anOrigin/Sec-Fetch-Sitecheck;HEADfalls back toGET; other methods get 405 withAllow. Request bodies now reach the handler in dev andvite preview. New type:RequestHandler. The CSRF check falls back toRefererwhen a write has noOrigin, refuses an opaqueOrigin: null, and refuses a write that carries cookies but neither header. #329 - Island HMR in
vite dev: saving an island's file swaps it in place with the page's new HTML and code, and its state (and that of islands inside it) carries over by name. Changes only the server sees, like pages, layouts, components without a<script>, loaders and Markdown pages, now reload the open page; before, the browser kept showing the old page. Builds carry none of it. #336 - A static (or client) route's
load()that readscookiesor the request's headers is now an error: "/account reads cookies, but static routes are built once for everyone: make it 'server'". Such a page used to be built once with whatever the build saw.clarusjs explainanddist/clarusjs-manifest.json(cookies: true) show which server routes read cookies. #328 - Template lint in
clarusjs check:unused-input,unused-import,img-alt,label-fieldandaccessible-name, reported as warnings atfile:line:col(the exit code changes only with--strict, or a rule set to'error'). Set levels with the plugin'slintoption, skip one place with{{-- clarusjs-ignore rule --}}, and add your own rules withlintRules(lint(),lintRulesandLintRuleDefare exported fromclarusjs/compiler). Every diagnostic now has aseverity, also in--json. The language server shows the built-in rules' findings as warnings. #337
Patch Changes
- Full-document pages: a comment (or BOM) before the doctype no longer adds a second one, and
<html>,</head>or</body>inside a<script>or<style>no longer count as the page's own tags (a page with one in an inline script got no default shell, or the loader in the wrong place). #313 vite buildno longer publishes Vite's manifest (dist/client/.vite/manifest.json) with the site.vite previewanswers a malformed URL with 400 instead of passing it on, and its built-page lookup compares against the output folder with a separator, so a path into a sibling folder (dist/clientx) can't be mistaken for a page of the site. #313vite build --watchworks: after each change undersrc/orpublic/, the client build, the server build and the prerender run again in order, so pages point at the rebuilt islands' new hashes (it used to fail looking for the server build). In dev, island URLs use forward slashes on Windows, and/@fs/URLs for components outside the root carry the drive (/@fs/C:/libs/c.tscl). #326