Repository navigation
Dars Framework v1.8.1
Release Notes v1.8.1
Style System Optimization & SSR-Aware Registry
Installation
pip install --upgrade dars-frameworkWhat's New
New Style Optimization Pipeline (Phase 1)
v1.8.1 introduces the first phase of a new style optimization system focused on reducing inline CSS while keeping full compatibility with Dars reactivity and dynamic operations.
- Static styles defined via
style={...}or Tailwind-like strings instyle="..."are now:- Parsed into CSS dicts by the exporter.
- Fingerprinted and converted into generated classes:
.dars-s-<hash>. - Emitted once into a central style registry instead of repeating large inline
styleblocks.
- The exporter automatically attaches the generated class to the component and clears the redundant inline style, resulting in:
- Smaller HTML output.
- Less DOM churn on updates.
- Better cacheability for repeated style patterns.
The original class_name remains fully respected and is appended after the generated dars-s-* class, so user classes (and external CSS frameworks) retain override power.
Central Style Registry in the HTML Head
The optimized styles are accumulated into a central registry and injected in the <head> as:
<link rel="stylesheet" href="runtime_css.css">
<style id="dars-style-registry">
/* .dars-s-* rules here */
</style>
<link rel="stylesheet" href="styles.css">Order is carefully chosen so that:
runtime_css.cssprovides the base UI tokens and default component styling.#dars-style-registrycontains all extracted.dars-s-*rules (including those coming fromhover_style/active_stylephases on future releases).styles.css(hover/active styles +app.add_global_style()+ user CSS files) comes last, ensuring user styles can override the framework-generated ones.
Full Export Coverage: Single/Multi Page, SPA & SSR
The new style pipeline now runs consistently across all export modes:
-
Single page & multipage:
HTMLCSSJSExporter.exportcollects static styles from the component tree before rendering.- The generated HTML includes the
#dars-style-registryblock in the head.
-
SPA export (
_export_spa):- Each SPA route runs the same static-style collection before serializing its
html. - The per-route config in
__DARS_SPA_CONFIG__now includes astylesfield containing the CSS for that route. - At runtime, the SPA router calls
_injectStyles(routeName, styles)so that SSR/SPA navigations share the same optimized classes.
- Each SPA route runs the same static-style collection before serializing its
-
SSR backend (
dars.backend.ssr):SSRRenderer.render_routeuses a deep copy of each route's root tree to avoid mutating the original components when collecting styles.- Static styles are extracted to
.dars-s-*classes, and the resulting CSS is injected into the SSR HTML head using#dars-style-registry. - The SSR JSON API (
/api/ssr/<route>) now returns astylesfield alongsidehtml,vdom,events, etc., so the SPA router can inject the same registry CSS on client-side navigations.
Runtime & Router Adjustments
The embedded JS runtime (dars/js_lib.py → DARS_MIN_JS) has been updated to be style-optimization aware without breaking existing behavior:
Dars.change({ id, dynamic: true, style: {...} })and state rules that manipulateattrs.stylecontinue to write directly toel.style[...].- They do not depend on an initial inline
styleattribute, so elements whose base styles were moved to.dars-s-*remain fully reactive.
- They do not depend on an initial inline
- Class updates via
attrs.classpreserve internaldars-*classes (including.dars-s-*) and only replace user classes, ensuring the optimization never gets wiped by state changes. - The SPA router:
- Loads SSR route data from
/api/ssr/...and now respects thestylespayload from the backend. - Uses
_injectStyles(routeName, styles)on every SSR navigation so that optimized classes stay active even after client-side route changes.
- Loads SSR route data from
These changes are designed to be backwards compatible for projects that used only style/class_name and dynamic state. The main effect you will notice in v1.8.1 is smaller, cleaner HTML with fewer repeated inline styles, especially for static or Tailwind-like styling.