Reference › Project
clarusjs 0.14.0
All releases · [email protected] on npm
Minor Changes
@await (promise) { pending } @then (value) { … } @catch (error) { … }([#430](https://github.com/forinda/clarusjs/issues/430)). In an island the server renders the pending branch and the browser swaps in@thenor@catchwhen the promise settles; when the expression's signals change a new promise starts, and only the newest one's answer shows. Outside islands the server awaits it and renders@thenor@catchinto the HTML (without@catch, a rejection fails the render). It reuses the@ifblock markers (<!--[bN:0-->).clarusjs checktypes@then's name as the promise's value. #438clarusjs/fetch:action(), for one-off async calls such as save, delete or like ([#429](https://github.com/forinda/clarusjs/issues/429)). It haspending,errorandresultfor the template.run(input)never rejects (a failure lands inerrorand the callbacks);runAsync(input)does. A call while one runs joins it (no double submit), or withconcurrency: 'latest'cancels it. It takesabort(),timeout,onSuccess/onError/onSettled(with the input), andmetaforconfigure()'s handlers. Created in an island, a call in flight is cancelled when the island goes away. A resource's or action'stimeoutis reported as aTimeoutErroreven when the client rejects with its own error on abort (axios:CanceledError). The Fetching guide shows axios, ky or your own client withresource()andaction(). #435clarusjs/fetch: any response, cancelling, timeouts and error callbacks ([#431](https://github.com/forinda/clarusjs/issues/431)). -request(url, options)reads the body by itsContent-Type(JSON forapplication/jsonand+json, text fortext/*and XML, else aBlob;undefinedfor a 204), or asassays (json,text,blob,arrayBuffer,formData,stream,response);parseadds your own readers per content type. A plain object or arraybodyis sent as JSON. A non-2xx response throws withstatusanddata(the error body).timeoutaborts with aTimeoutError.assets the result's type (text:string,response:Response…).json()and the newtext()are its shorthands; ajson()error now hasdatatoo. -resource():abort()cancels the run in flight (not an error),timeoutfails a slow run (an error), andonSuccess/onError/onSettledrun once per request, withmeta. -configure({ onSuccess, onError }): handlers every resource calls after its own callbacks, for toasts in one place; a callback returningfalseskips them. #434<script server>: code that runs on the server while a page or component renders, and canawait([#430](https://github.com/forinda/clarusjs/issues/430)). Its names are there for the template, its imports never reach the browser (node:modules too), and it doesn't make the component an island. A component that awaits there renders asynchronously; its parents join what it returns, and stay synchronous when nothing they contain awaits. It isn't allowed in an island, inside one, or in a client route (located errors). The request handler,render()andh()fromclarusjs/viewsawait async renders, and component loaders' data now stays with its own render acrossawaits (AsyncLocalStorage). An island's<script>still can'tawaitat the top level; its error now names<script server>andresource(). #437
Patch Changes
- In
vite dev, every page loads Vite's client, islands or not. A page without islands loaded no JavaScript at all, so edits to its styles, its layout or a global stylesheet never reached the browser until a manual reload. #445 - A
.tsclfile imported with?raw,?urlor?inline(a code sample, a playground example) is left to Vite instead of being compiled as a component, which failed the build. #441