Reference › Project
clarusjs 0.3.0
All releases · [email protected] on npm
Minor Changes
- Components inside islands: an island's template can use other components, including inside
@ifbranches and@forrows. A component without a script is re-rendered in the browser when the props or slot content it gets from the island change (its server render function is imported with the plugin's new?renderquery). A component with a script is its own island, keeps its own state and starts from the props it was first given; islands inserted later are attached automatically. #68 - Dynamic attributes: bind with
[name]="expression"on HTML elements or use{{ }}inside attribute values. Values are escaped, URL attributes never getjavascript:/vbscript:URLs,true/false/nulladd or remove boolean attributes, and attributes that read state update live inside islands.on*attributes are a build error; use(event)bindings. #59 @for (item of list; track key) { … } @empty { … }loops, with$index. Outside islands the list renders on the server. Inside an island rows are reconciled by key when the list changes: kept rows keep their elements (moved only when out of order) and receive the new item and index, new rows are rendered and wired, removed rows are disposed. Event handlers in a row get that row's item, and@ifblocks and attributes inside rows stay reactive. #66@if/@else if/@elseblocks. Outside islands the branch is chosen on the server and costs nothing in the browser. Inside an island the block switches when the state it reads changes: the server-rendered branch is wired in place, and a new branch is rendered in the browser and wired, with the old branch's effects and event handlers disposed. Signals gainscope(),onDispose()anduntrack(). #65- Islands start from the server's state: each island's
state()values are rendered into ansattribute andattachuses them, so initial values likeDate.now()aren't recomputed in the browser. Island props and state are serialized with Date, Map, Set, undefined, NaN, ±Infinity, -0 and BigInt support; functions, class instances and circular references are rejected with their path (NaN and Infinity in props now round-trip instead of being rejected). Island props and state are public (they are in the page), so an island script that reads server-only globals (process,Deno,Bun,require) is a build error. #68 - Lazy attach:
attach="idle",attach="visible"orattach="interaction"on a component tag delays loading an island's code until the browser is idle, the island scrolls into view, or someone uses it. In every mode, clicks, key presses, input and form submissions inside an island before it attaches are held and replayed afterwards, so nothing is lost while its code loads. Compiledrender()takes an options argument (render(props, slots, { attach })). #68 - Named slots:
<slot name="…">in a component, filled from the parent with@slot('name') { … }; everything else goes to the default slot. Content inside a<slot>is its fallback, shown when nothing fills it. Filling a slot the component doesn't have fails when rendering, naming the slot. Compiledrender()now takes its slot content as an object (render(props, slots)). #67 - Shared stores and imports in
<script>. Island scripts can nowimport(hoisted to the top of the compiled modules;node:imports are a build error since the script is bundled for the browser). A store is a module exportingstate()values;let items = shared(store)uses it in an island like local state, keeping every island that uses it in sync. On the server a shared value renders from the store's initial value, never its current one, so one request can't leak into another's page. Signals gain a read-onlyinitial. #68 verbatimelements: addverbatimto any HTML element (for example<pre><code verbatim>…</code></pre>) and its content is shown as text, with no holes, tags or directives inside. Useful for code samples. #59
Patch Changes
- URL checks now cover every entry of list-valued attributes: each space-separated URL of
ping, and each;-separated entry ofvalueson SVG animation elements. SVG animation attributes (to,from,values,by) are only URL-checked on<animate>,<set>,<animateMotion>and<animateTransform>; on other elements they are ordinary data. #64 - Safer URL attributes: bound and interpolated URL attributes now use an allowlist (relative URLs,
http:,https:,mailto:,tel:, and rasterdata:images for image attributes) instead of refusing onlyjavascript:/vbscript:. More URL-bearing attributes are checked (data,codebase,ping,manifest,longdesc, SVG animation values), everysrcsetcandidate is checked, and bindingsrcdocis a build error. #63